views:

1035

answers:

2

Ok something ultra strange is going on here...

I just added a transaction scope around some legacy code i was debugging to ensure the fiddling I was doing wouldn't get committed.

This worked twice, then said:

"The transaction manager has disabled its support for remote/network transactions."

without any code changes or rebuilds between the working/nonworkingness (literally 3 F5s in a row [web app]). This was local code connecting to a remove db server.

Since this, completely separate code in a different project is timing out. If I remove the transactionScopes from this code it runs fine, but with them in place it times out. I've tried my local sql server and remote ones, both time out inside the transactionscope.

What the hell is going on?

Edit: I've found that changing my TransactionScopes from:

using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))

to

using (var scope = new TransactionScope())

prevents the problem :s

What does this mean?

Thanks

Andrew

A: 

I believe what is happening when the error occurs is that the framework is trying to promote the original "lightweight" (i.e. DBMS) transaction to a "distributed" transaction. The MSDTC (Distributed Transaction Coordinator) service, which manages distributed transactions, is either not running or is otherwise not able to work.

This typically happens when one logical transaction spans two (or more) database connections. Of course, in your case there is (apparently) only one DBMS connection. I'm guessing by forcing a new, independent transaction scope you are also forcing the framework to use a distributed transaction.

Daniel Pratt
this guy has a very similar problem, if this sheds any more light http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.adonet/topic62511.aspx
Andrew Bullock
+3  A: 

The difference between:

using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))

and

using (var scope = new TransactionScope())

Is that the second one reuse the existing (ambient) transaction, whereas the first one creates a new transaction within an old one.

This transaction within a transaction requires the Distributed Transaction Coordinator.

There are then three probable reasons for your error:

  • The MSDTC is not running
  • Your database is on a different machine and windows is configured not to allow transactions from the network.
  • Your database is on a different machine and SQL server is configured not to allow transactions from the network
Shiraz Bhaiji
+1 for pointing out that "new TransactionScope()" is equivalent to "new TransactionScope(TransactionScopeOption.Required)" - it can make all the difference.
Yoopergeek