MSDTC问题的ADO.NET实体框架的交易实体、框架、问题、MSDTC

2023-09-05 00:13:47 作者:  ‘ 傻头-。 | ‘ 傻恼-。

在我们目前的项目中,我们使用ADO.NET实体框架的数据层应用程序。还有一些任务需要在一个事务中运行,因为有很多工作要做在数据库中。我使用的是 TransactionScope的围绕这些任务。

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();
}

问题尽快是因为我使用的是的TransactionScope 发生异常:

System.Data.EntityException:基础提供程序未能打开。 ---> System.Transactions.TransactionManagerCommunicationException:与基础事务管理器通信失败。 ---> System.Runtime.InteropServices.COMException(0x80004005的):错误HRESULT E_FAIL已返回通过调用COM组件

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.

看来,这个错误必须做一些与 MSDTC (Microsoft分布式事务处理协调器)。当我更改MSDTC的安全配置抛出了另一个错误:

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:基础提供程序未能打开。 ---> System.Transactions.TransactionManagerCommunicationException:网络访问分布式事务管理器(MSDTC)已被禁用。请启用DTC中使用的组件服务管理工具MSDTC安全配置的网络访问。

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.

不过MSDTC配置,在的TransactionScope 会会导致错误。 是否有人知道怎么回事错在这里?

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

推荐答案

嗯,似乎工作,当我改变的 TransactionScopeOption 以燮preSS:

Hmm, it seems to work when i change the TransactionScopeOption to "Suppress":

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

请问大家知道为什么吗?

Does everyone know why?