In my code there are transactions to handle:
using (var scope = new TransactionScope())
{
repo1.SaveSomething();
repo2.SaveAnythingElse();
scope.Complete();
}
Inside repo1 and repo2 functions create their own db context with using, and dispose them, the transactions worked like a charm.
Now I add another code like this, and it begins to drop an exception:
The underlying provider failed on Open. (EntityFramework) 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. (System.Transactions) The transaction manager has disabled its support for remote/network transactions.
I read that when connections are opened inside transaction despite of the same sql server same db - it needs the MSDTC component to handle it. I changed the code to the following:
using (var scope = new TransactionScope(TransactionScopeOption.Required,
new TransactionOptions() { IsolationLevel = IsolationLevel.ReadCommitted }))
{
....
scope.Complete();
}
And now the exception disappears.
My questions:
- why the transactions used in the code earlier never drop the exception?
- why the new code drops it?
- after the change why it drops no more?
Easy questions I think :) Any help would be appreciated!