C# Entity Framework : TransactionScope over two different databases on same server with DTC

标签 c# entity-framework distributed-transactions

我的情况与此处描述的情况基本相同 Multiple databases(datacontext) on same server without MS DTC

喜欢:

using (var transaction = new TransactionScope())
{
    using (var entities = new ContextA())
    {
        // do smth. here
    }

    using (var entities = new ContextB())
    {
        // do smth. there
    }
}

ContextB 和 ContextA 都位于同一个 MS SQL Server (V. 13.0.4206.0) 上。 C# 代码从远程工作站执行。服务器和工作站都在同一个域网络中。 但是,当 ContextB 尝试进行第一次操作时,它会引发以下错误:

The MSDTC transaction manager was unable to pull the transaction from the source transaction manager due to communication problems. Possible causes are: a firewall is present and it doesn't have an exception for the MSDTC process, the two machines cannot find each other by their NetBIOS names, or the support for network transactions is not enabled for one of the two transaction managers. (Exception from HRESULT: 0x8004D02B)

如果我改变任务的顺序没有任何区别;先说做在 ContextB 上,然后在 ContextA 上:在这种情况下,从 ContextA 操作数据库时会出现错误。 没有交易范围一切正常(但当然没有交易)。 我检查了服务器上的防火墙设置:为域和专用网络启用了分布式事务处理协调器的预定义规则。我还检查了 DTC 属性:

网络 DTC 访问:真

允许入站:true

允许出站:真

怎么了?看起来很简单,我是不是监督了什么?

感谢您的回答。

最佳答案

已解决:需要在运行 C# 代码的 Worksation 上激活预定义的防火墙规则“分布式事务协调器”。

我不知道数据库服务器会打开一个返回到事务初始值设定项(这是我的工作站)的连接。在这种情况下,事务初始化器似乎继承了协调器的角色,而不是服务器。

感谢您的提示!

关于C# Entity Framework : TransactionScope over two different databases on same server with DTC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49065832/

相关文章:

c# - 为什么在使用接口(interface)继承时动态绑定(bind)会失败?

c# - 在MVC中使用Entity Framework是否需要实现IDisposable?

entity-framework - Entity Framework - 如果 SaveChanges 失败并且我不想进行某些更改该怎么办?

oracle - "ORA-14450: attempt to access a transactional temp table already in use"在复合触发器中

sql-server - 具有多个 DbContext 的事务,每个事务在 Entity Framework 上都有自己的连接

c# - 在 mvc View 中循环遍历对象?

c# - 在asp.NET C#中导入Excel文件时日期格式丢失

.net - Entity Framework -是否可以在EDMX设计器中对属性进行重新排序?

c# - 使用 webAPI Bearer Token 的 SignalR 身份验证