I have the following code:
var scopeOption = TransactionScopeOption.RequiresNew;
var transactionOptions = new TransactionOptions
{
IsolationLevel = IsolationLevel.ReadUncommitted
};
using (new TransactionScope(scopeOption, transactionOptions))
{
var context = new ObjectContext("connection string");
context.Connection.Open(); // <-- This line throws
}
It throws the following exception:
System.Data.EntityException: The underlying provider failed on Open.
Caused by: System.Data.SqlClient.SqlException, MSDTC on server 'xxxx' is unavailable.
But it only throws the exception the on the first attempt to open the connection. Any subsequent calls to the example code work perfectly and don't try to contact the DTC.
Note: Changing scopeOption
to TransactionScopeOption.Suppress
seems to fix the issue, and as I'm not performing any writes to the database is more than acceptable.
Can anybody think of why opening the first (and only) connection in a brand-new TransactionScope
would cause a DTC escalation only the first time the code is invoked?