I am using System.Transactions.TransactionScope()
in a unit test to insert a record, attempt to read it, and let the transaction scope rollback so as to leave no footprints behind in the database.
1 var rep = new RunRepository();
2 using (var scop = new TransactionScope())
3 {
4 var runId = rep.SaveSwrsRun([Run data elements]); // returns PK RunId
5 var run = rep.FetchSwrsRun(runId); // returns an object of type Run
6 Assert.IsNotNull(run);
7 }
Line 5 throws an exception, with error message
System.Transactions.TransactionManagerCommunicationException : 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.
I have checked the Component services Admin tool, and my workstation does have DTC enabled. I also discovered this MSDTC Transaction scope problems thread, which directs me to How to enable Network DTC Access
But when I checked the SQL server the remote access checkbox was already checked . Anyone else have any other ideas ?
More details... When I force the Repository to hold on to the same connection, and not go back to the pool for another one for the second Sql statement, it works. Apparently, using a different connection for the second sql statment is triggering the DTC to escalate the transaction into "distributed Mode" (which it should not, since both sql statements are on the same server, and use the exact same connection string), not to mention that even if it did, that (distributed mode) still ought to work anyway.