将 MSDTC 与实体框架结合使用时出现提供程序故障

发布于 2024-08-06 06:59:53 字数 742 浏览 1 评论 0原文

我有一个应用程序,可以保存到数据库(使用实体框架)并在一次保存中将文档保存到 Sharepoint。我正在尝试将 MSDTC 与 TransactionScope 一起使用。

我的 EF 插入逻辑的一部分包括将外键列表传递到数据层。该层从数据库中检索“外键”对象,然后将其添加到主对象中。奇怪的是,这对于第一个外键项目可以正常工作,但在第二个项目上失败并显示以下消息。

System.Data.EntityException:底层提供程序在打开时失败。 ---> System.Transactions.TransactionManagerCommunicationException:分布式事务管理器(MSDTC)的网络访问已被 禁用。请在安全中启用DTC以进行网络访问 使用组件服务管理配置 MSDTC 工具。

MSDTC 在第一次通过期间启用并工作,但在第二次期间则不再工作。我认为当我进行多次选择调用时,上下文会以某种方式变得混乱?

这是我的逻辑:

//Create new order

foreach(int lineItemId in lineItems)
{
   //Retrieve the LineItem object from db
   //Add the LineItem object to the Order
}

//Save using EF

也许我不应该从数据库检索对象?我是否缺少一种引用 EF 中关系的简单方法?

I have an app that is saving to a db (using Entity Framework) and saving documents to Sharepoint in a single save. I'm attempting to use MSDTC with a TransactionScope.

Part of my EF insert logic includes passing a list of foreign keys to the data layer. The layer retrieves the "foreign key'd" object from the db and then adds it to the primary object. The strange thing is, this works correctly for the first foreign key'd item, but fails on the second with the following message.

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 is enabled and works during the first pass through, but not the second. I assume the context is somehow getting confused when I am making several select calls?

Here's my logic:

//Create new order

foreach(int lineItemId in lineItems)
{
   //Retrieve the LineItem object from db
   //Add the LineItem object to the Order
}

//Save using EF

Perhaps I shouldn't be retrieving the object from the db? Am I missing a simple way to reference the relationship in EF?

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

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

发布评论

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

评论(2

℡寂寞咖啡 2024-08-13 06:59:53

您需要数据库服务器、Sharepoint 服务器以及运行要运行的代码的计算机上的 DTC 并启用网络访问(右键单击组件中分布式事务协调器节点上的“属性”)服务管理单元,确保选中网络 DTC 访问,并在每台计算机上选中允许远程客户端以及入站和出站通信(您可以删除一些 第一个调用之所以

有效,是因为它只与本地 DTC 通信 - 一旦它尝试使用远程 DTC 来登记 tx,它就会失败。

You'd need the DTC on the DB server, the Sharepoint server, and the machine running the code to be running and enabled for network access (right-click Properties on the Distributed Transaction Coordinator node in the Component Services snap-in, ensure Network DTC Access is checked and that Allow Remote Clients and Inbound and Outbound communications are checked on each of the machines (you may be able to remove some of these, but get it working first).

The first call works because it's only talking to the local DTC- as soon as it tries to enlist the tx with a remote DTC, it fails.

简美 2024-08-13 06:59:53

这实际上与 Matt 的答案相同,但以图形方式

在此处输入图像描述

This is effectively the same answer as Matt's but graphically

enter image description here

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