当我只使用 LinqToSql 和 Ado.Net 时,为什么 TransactionScope 使用分布式事务

发布于 2024-08-30 19:55:29 字数 263 浏览 3 评论 0原文

我们在一台机器上遇到问题,并显示错误消息:

“服务器 XXX 上的 MSDTC 不可用。”

该代码使用 TransactionScope 来包装一些 LingToSql 数据库代码;交易内部还有一些原始的 Ado.net。

由于仅访问单个 SQL 数据库(2005),为什么要使用分布式事务?

(我不想知道如何启用 MSDTC,因为代码需要在具有当前设置的服务器上运行)

We are having problems on one machine, with the error message:

"MSDTC on server XXX is unavailable."

The code is using a TransactionScope to wrap some LingToSql database code; there is also some raw Ado.net inside of the transaction.

As only a single sql database (2005) is being accessed, why is a distributed transaction being used at all?

(I don’t wish to know how to enable MSDTC, as the code needs to work on the server with their current setup)

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

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

发布评论

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

评论(1

悲喜皆因你 2024-09-06 19:55:29

当您的事务使用多个数据库连接时,这种情况几乎总是会发生。因此,假设您要更新两个表。您可以使用一个连接更新第一个表,但使用不同的第二个连接更新第二个表。这将导致事务升级到 MSDTC,即使使用 TransactionScope 对象也是如此。

我们解决这个问题的方法是在执行事务时,我们使用单个数据库上下文对象来进行所有写入。这消除了升级。自从这样做以来,我们再也没有出现过 MSDTC 消息。

兰迪

This almost always happens when your transaction uses more than one database connection. So, let's say you are updating two tables. You might update the first table using one connection but update the second table using a different second connection. This will cause the transaction to be escalated to MSDTC, even using a TransactionScope object.

The way we got around this is when performing transactions, we use a single database context object for all our writes. This eliminated the escalation. Since doing this, we've never had the MSDTC message appear.

Randy

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