Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSDTC issue with transactions in ADO.NET Entity Framework

in our current project we are using ADO.NET Entity Framework as data layer for the application. There are some tasks which require to run in a transaction because there's a lot of work to do in the database. I am using a TransactionScope to surround those tasks.

using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
    // Do something...
    transactionScope.Complete();
}

The problem is as soon as i am using an TransactionScope an exception occurs:

System.Data.EntityException: The underlying provider failed on Open. ---> System.Transactions.TransactionManagerCommunicationException: Communication with the underlying transaction manager has failed. ---> System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.

It seems that this error has to do something with the MSDTC (Microsoft Distributed Transaction Coordinator). When I change the security configuration of MSDTC another exception is thrown:

System.Data.EntityException: The underlying provider failed on Open. ---> 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.

However MSDTC is configured, the TransactionScope will cause an error. Does somebody know whats going wrong here?

like image 403
Alexander Avatar asked Oct 23 '09 07:10

Alexander


2 Answers

By default MSDTC has network access disabled. To get it working you should go to

Control Panel-> Administrative Tools->Component Services->Component Serivces->Computes->My computer->Right click->Properties->MSDTC->Security Configuration

and check following checkboxes Network DTC Access, Allow Inbound, Allow Outbound. Authentification should be chosen according to you environment. You might also want to take a look at DTCPing tool to debug distributed transactions. To give you a shortcut - you may need to modify you registry:

HKLM\Software\Policies\Microsoft\Windows NT\RPCRestrictRemoteClients=0 HKLM\Software\Policies\Microsoft\Windows NT\RPCEnableAuthEpResolution=1

to get everything up and running.

like image 122
Nikolay R Avatar answered Sep 30 '22 13:09

Nikolay R


Yes, it works using Supress, because you are telling it to supress or ignore the ambient transaction and create a new local transaction. Since the transaction is local it is not a distributed transaction so its not using MSDTC, but you probably shouldn't use Suppress and should use Required instead.

like image 22
Bill Avatar answered Sep 30 '22 12:09

Bill