0
votes

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.

1
Besides having Network DTC Access enabled are the rest of the settings configured (on both servers) as per How to enable Network DTC Access? e.g. Allow Inbound, Allow Outbound etc.Randy supports Monica
yes, both Inbound and Outbound check boxes are selected... Everything looks ok...Charles Bretana
Are you using SQL Server 2005 or higher? If so, then, as you say, you shouldn't see transaction escalation. Is it possible that the repository is not closing the connection after the save?Randy supports Monica
For the DTC issues, I would try DTCPing ( download.microsoft.com/download/d/0/0/… ) to see if it can give any additional information. I'm not sure if it will help since it is usually most useful when the messages are more cryptic. See blogs.msdn.com/b/distributedservices/archive/2008/11/12/… for a nice walk through.Randy supports Monica
Using sql 2008, and as noted above, If I use the same connection the issue goes away, so it seems what is happening is that even though connections strings are identical, if you run two queries on different connections, the transaction automatically gets escalated, (Which I do not think should happen!) The, second issue, is why theescalted transaction is failing (network MSDTC connectivity issue somewhere...)Charles Bretana

1 Answers

0
votes

If your DTC service has run, click security configuration and check "Network DTC Access" on Security setting region. See image bellow. Network DTC Access