Linq DataContext – Network access for Distributed Transaction Manager (MSDTC) has been disabled

12 January 2012 at 15:13

For the purpose of testing our DataContext interactions we have a base class that sets up a TransactionScope on a generic DataContext. I had a problem where the transaction was escalated to a distributed transaction - fine on my machine but the build server wasn't happy throwing this error for my new tests:

Transaction Manager Communication Exception : Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool.

Why was it escalated? Because I was using more than one connection in the transaction. Our base class prevented this by manually opening the connection in the TestFixture Setup function, however the code was calling a function that created its own DataContext of the same type. The solution was to pass the DataContext into this function rather than having it create one itself. Of course preferably we would inject an interface of a repository to decouple the persistence but the Guardian of the Code would not allow that in this case.

Triynko posted this to stackoverflow, question three is most relevant, whilst Rick Strahl goes over transactions and linq in this post with a good explanation of escalation.