Inconsistent behaviour with distributed transaction (MSDTC exception)

0

You may think this has been asked before, but hear me out first.

I have a project that runs across different servers with remote connections. On the development server, all tests pass.

In the QA server that has same configuration, most tests pass but a couple fail and the exception is

The underlying provider failed on Open.

Inner 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.

Inner inner exception:

The transaction manager has disabled its support for remote/network transactions. 
(Exception from HRESULT: 0x8004D024)

As far as I can see the configuration is correct and in fact the tests that pass run the exact same code without issues so there are no configuration issues related to MSDTC.

The piece of code that causes this is an entity framework connection that adds a simple row to a database table:

using (var inbound = new InBound.InBound())
{
    var now = DateTime.Now;
    var inMessage = inbound.InMessages.Create();
    inMessage.Content = message.ToXmlFormattedString();
    inMessage.Created = now;
    inMessage.SerializedVersion = version;
    inMessage.Updated = now;
    inbound.InMessages.Add(inMessage);
    inbound.SaveChanges(); //Exception here
 }

This same piece of code does its job on some tests, but fails in a few others. This problem only occurs on the QA environment. All MSDTC related configuration has already been checked and appears correct. DEV environment has the same configuration and this error doesn't happen.

The environment is identical. Microsoft Server 2012 R2, MS SQL Server 2008, same codebase, same settings.

The xml in the message is the same in both the test that fails and the test that passes.

I've exhausted the list of places I can look for a solution and there seems no logical explanation at all for this.

Any ideas?

UPDATE

If I add "Enlist=false" in the connection string then the tests pass again. However I do get an internal exception that gets drowned and that is:

Cannot enlist in the transaction because a local transaction is in progress on the connection. Finish local transaction and retry.

so the connection must be open somehow, even though during debugging the state of the database is "closed".

c#
entity-framework
sql-server-2008
distributed-transactions
asked on Stack Overflow Mar 7, 2016 by Nick • edited Oct 12, 2016 by krlzlx

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0