views:

29

answers:

1

Background: I have an ASP.NET MVC application that wraps controller actions in a TransactionScope using an Action Filter.

Further downstream (in my infrastructure layer); I'd like to open up a new ADO.NET connection (to the same db as my outer TransactionScope, if that is relevent) and have it participate in its own transaction - without being tied to the current TransactionScope started at the controller level; how do I go about doing this?

+1  A: 

You pass in TransactionScopeOption.RequiresNew:

TransactionOptions to = new TransactionOptions;
to.IsolationLevel = <desiredIsolationLevel>;
using (TransactionScope scope = new TransactionScope(
   TransactionScopeOption.RequiresNew, to))
{
  ... do work here
  scope.Complete ();
}

Be carefull though, there be dragons under that bridge. Specifically is easy to deadlock with yourself if the encompassing scope has pending uncommitted writes from its own transaction scope and you attempt to touch the very same entities in the inner standalone transaction (the new scope).

Remus Rusanu
@Remus: I'd be using ReadUncommitted; and only using this for a performance-critical read operation (basically to perform an ungodly, complex export) - so I assume it wouldn't be an issue in this specific instance, right?
DanP

related questions