Transactional MSDTC issue in Entity Framework ADO.NET

in our current project, we use the ADO.NET Entity Framework as the data layer for the application. There are several tasks that require a transaction because there is a lot of work in the database. I use TransactionScope to combine these tasks.

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

The problem is that when I use TransactionScope , an exception is thrown:

Fix System.Data.EntityException: The underlying provider does not work in Open. ---> System.Transactions.TransactionManagerCommunicationException: Communication with the main transaction manager failed. ---> System.Runtime.InteropServices.COMException (0x80004005): HRESULT error E_FAIL was returned from a call to the COM component.

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

System.Data.EntityException: Open. --- > System.Transactions.TransactionManagerCommunicationException: Distributed Transaction Manager (MSDTC) . DTC MSDTC .

MSDTC , TransactionScope . - , ?

+5
8

, , , TransactionScopeOption "":

using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Suppress))
{
    ...
}

?

-2

MSDTC . ,

- > - > - > Serivces- > Computes- > - > a > - > MSDTC- >

: DTC, , . . DTCPing . - :

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

.

+7

, Supress, , . , , MSDTC, , , Suppress Required.

+3

, , , , "" .

0

, :

MSDTC

Nikolay R. , .

. Biztalk, , MSDTC.

0

" Entity Framework , Entity Framework , , MSDTC."

.

, : MSSQL. '

0

, , , - .

, , : ? , 1 ?

, DTC, .

, . , . , , , System.Transactions , MSDTC. : MSDN

, , , :

//Create rootScope
using(TransactionScope rootScope = new TransactionScope()) 
{ 
    using(TransactionScope scope2 = new 
    TransactionScope(TransactionScopeOption.Required)) 
    {
         //Do work on DB1
         ...

         //Complete this ambient transaction
         scope2.Complete();
    } 

    using(TransactionScope scope3 = new 
    TransactionScope(TransactionScopeOption.Required)) 
    {
         //Do work on DB2
         ...

         //Complete this ambient transaction
         scope3.Complete();
    } 

    //Complete rootScope
    //The whole transaction will only be committed if you call 
    //Complete on the rootScope
    rootScope.Complete();

}

TransactionScopes, , ,... MSDN.

, .

0

If the Distributed Transaction Coordinator service is not running, the Entity infrastructure cannot connect to the database. Open and run Distributed Transaction Coordinator

Services → Distributed Transaction Coordinator

0
source

All Articles