从 NServiceBus 方法调用实体框架会导致错误

发布于 2024-12-15 04:25:33 字数 1360 浏览 0 评论 0原文

我有一个具有自托管 WCF 服务的解决方案。该服务连接到 EF 并且可以正常读写。

在同一解决方案中,我还托管一个 NServiceBus 端点。它从单独运行的解决方案获取事件。

当我运行 NServiceBus 项目(单独)时,它似乎工作正常,直到我尝试查询数据库。当我这样做时,我得到这个 EntityException:

底层提供程序在打开时失败。

内部异常是一个 TransactionException,其消息如下:

合作伙伴事务管理器已禁用对远程/网络事务的支持

我的 NServiceBus 和 WCF 服务项目都使用完全相同的配置和 EF 项目。我不明白为什么一个失败而另一个没有。

我做了一些谷歌搜索,发现了这个页面: http: //msdn.microsoft.com/en-us/library/aa561924%28BTS.20%29.aspx 向我展示了如何设置MSDTC,我是在我的客户端计算机上完成的。但没有效果。

我还发现这个问题说需要设置:NServiceBus:系统.Transactions.TransactionException:合作伙伴事务管理器已禁用对远程/网络事务的支持。但它没有说为什么或在哪里。

我需要在数据库服务器上设置 MSDTC 吗?如果是这样,为什么?什么是 MSDTC?

为什么从 NServiceBus 托管进程运行会导致此错误?

更新:我发现了这个 链接帮助我了解 DTC 的作用。它还向我展示了如何在需要时将其关闭:

using (TransactionScope sc=new TransactionScope(TransactionScopeOption.Suppress))
     YourDatabaseHandler.SaveMyStuff(whatever);

尽管这听起来在很多情况下都是一件好事。

I have a solution that has a self hosted WCF Service. That service connects to EF and can read and write just fine.

In the same solution I also host an NServiceBus endpoint. It gets event from a separate running solution.

When I run the NServiceBus project (by itself) it seems to be working fine, until I try to query my database. When I do that I get this EntityException:

The underlying provider failed on Open.

The inner exception is a TransactionException with a message of:

The partner transaction manager has disabled its support for remote/network transactions

Both my NServiceBus and WCF Service projects are using the exact same configurations and EF Projects. I don't get why one is failing and the other is not.

I did some Googling and came across this page: http://msdn.microsoft.com/en-us/library/aa561924%28BTS.20%29.aspx that showed me how to setup MSDTC, and I did it on my client machine. But it had no effect.

I also found this question that says it needs to be set: NServiceBus: System.Transactions.TransactionException: The partner transaction manager has disabled its support for remote/network transactions. But it does not say why or where.

Do I need to setup MSDTC on my db server? If so, why? What is MSDTC?

Why does running from an NServiceBus hosted process cause this error?

UPDATE: I found this link that helped me understand what DTC does. It also showed me how to turn it off if needed:

using (TransactionScope sc=new TransactionScope(TransactionScopeOption.Suppress))
     YourDatabaseHandler.SaveMyStuff(whatever);

Though it sounds like it is a good thing in many situations.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南街九尾狐 2024-12-22 04:25:33

由于 NSB 使用事务队列,因此您将参与分布式事务。这意味着每台参与的机器都必须投票决定是否完成交易。这是通过分布式事务协调器 (MSDTC) 完成的。这必须在两台机器上运行(如果您使用其他数据库,例如 Oracle,则有一项附加服务)。要管理 MSDTC,请转到组件服务 ->计算机 ->我的电脑 ->分布式事务协调器->本地故障码。右键单击该节点,您将找到包括安全性在内的所有配置。

Since NSB is using a transactional queue, your going to be participating in a distributed transaction. This means that each machine participating will have to vote on whether or not to complete a transaction. This is done via the Distributed Transaction Coordinator(MSDTC). This will have to be running on both machines(and if you are using other DBs like Oracle there is an additional service). To manage MSDTC, go to Component Services -> Computers -> My Computer -> Distributed Transaction Coordinator -> Local DTC. Right clicking on that node you will find all the configuration including security.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文