MSDTC 中禁用网络访问

发布于 2024-10-07 13:31:21 字数 1053 浏览 0 评论 0原文

我在单元测试中使用 System.Transactions.TransactionScope() 来插入一条记录,尝试读取它,并让事务范围回滚,以便在数据库中不留下任何痕迹。

1  var rep = new RunRepository();
2  using (var scop = new TransactionScope())
3  {
4     var runId = rep.SaveSwrsRun([Run data elements]); // returns PK RunId
5     var run = rep.FetchSwrsRun(runId);  // returns an object of type Run
6     Assert.IsNotNull(run);
7  }

第 5 行引发异常,并显示错误消息

System.Transactions.TransactionManagerCommunicationException :分布式事务管理器 (MSDTC) 的网络访问已被禁用。请使用组件服务管理工具在 MSDTC 的安全配置中启用 DTC 进行网络访问。

我已检查组件服务管理工具,并且我的工作站确实启用了 DTC。我还发现了这个 MSDTC 事务范围问题 线程,它引导我到 如何启用网络 DTC 访问

但是当我检查 SQL 服务器时,远程访问复选框已被选中。还有其他人有其他想法吗?

更多详细信息...当我强制存储库保留相同的连接,并且不返回池以获取第二个 Sql 语句的另一个连接时,它会起作用。显然,对第二个 sql 语句使用不同的连接会触发 DTC 将事务升级为“分布式模式”(不应该这样做,因为两个 sql 语句位于同一服务器上,并且使用完全相同的连接字符串), 更不用说即使确实如此,(分布式模式)仍然应该可以工作。

I am using System.Transactions.TransactionScope() in a unit test to insert a record, attempt to read it, and let the transaction scope rollback so as to leave no footprints behind in the database.

1  var rep = new RunRepository();
2  using (var scop = new TransactionScope())
3  {
4     var runId = rep.SaveSwrsRun([Run data elements]); // returns PK RunId
5     var run = rep.FetchSwrsRun(runId);  // returns an object of type Run
6     Assert.IsNotNull(run);
7  }

Line 5 throws an exception, with error message

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.

I have checked the Component services Admin tool, and my workstation does have DTC enabled. I also discovered this MSDTC Transaction scope problems thread, which directs me to How to enable Network DTC Access

But when I checked the SQL server the remote access checkbox was already checked . Anyone else have any other ideas ?

More details... When I force the Repository to hold on to the same connection, and not go back to the pool for another one for the second Sql statement, it works. Apparently, using a different connection for the second sql statment is triggering the DTC to escalate the transaction into "distributed Mode" (which it should not, since both sql statements are on the same server, and use the exact same connection string),
not to mention that even if it did, that (distributed mode) still ought to work anyway.

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

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

发布评论

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

评论(1

残疾 2024-10-14 13:31:21

如果您的DTC服务已运行,请单击安全配置并在安全设置区域中勾选“网络DTC访问”。参见下图。
网络 DTC 访问

If your DTC service has run, click security configuration and check "Network DTC Access" on Security setting region. See image bellow.
Network DTC Access

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