没有 MSDTC - 仍然收到“与底层事务管理器的通信失败”消息

发布于 2024-09-13 03:01:53 字数 266 浏览 3 评论 0原文

在我的项目中,我使用 Ado.Net 的 DbTransaction 对象来管理事务...那么为什么我收到 MSDTC 相关错误 - “与底层事务管理器的通信失败”。

这是我的代码。

DbTransaction trans = Connection.BeginTransaction();

//Code

if (successfull)
{
    trans.Commit();
}
else
{
    trans.RollBack();
}

In my project I am using Ado.Net's DbTransaction object to manage transaction... Then why I am getting MSDTC related error - "communication with underlying transaction manager failed".

Here is my code.

DbTransaction trans = Connection.BeginTransaction();

//Code

if (successfull)
{
    trans.Commit();
}
else
{
    trans.RollBack();
}

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

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

发布评论

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

评论(1

倾城泪 2024-09-20 03:01:53

不幸的是,建立 MSDTC 确实很麻烦。然而,一旦你开始使用它,它就会工作得很漂亮。问题的出现只是因为每个人的网络设置都略有不同。

听起来您的 MSDTC 服务可能未在您的客户端计算机或服务器上启用。

以下是在 Windows 7 上启用它的指南: --> http://www.thereforesystems.com/turn-on-msdtc-windows -7/

您还需要在数据库服务器上启用它: --> http://support.microsoft.com/kb/817064

一种简单的方法来测试它是否无需联系服务器管理员的方法是在您的开发盒上设置两个不同的本地数据库。然后尝试在两个数据库连接之间维护事务。假设您正确配置了 msdtc,一切都应该正常工作。

最后一点是,您可以通过引用 System.Transactions 库并使用如下所示的事务代码来让您的生活变得更轻松:

using (TransactionScope scope = new TransactionScope())
{
    /* Perform transactional work here */
    SomeMethod();
    scope.Complete();
}

请注意,不需要显式回滚。如果 using 语句内发生任何崩溃,或者如果您在点击 .Complete(); 之前退出 using 语句,您的事务将回滚。有关 TransactionScope 的更多信息,请参见此处:--> http://msdn.microsoft.com/en-us /library/ms172152(VS.90).aspx

Unfortunately, MSDTC can really be a bear to set up. Once you have it going, however, it works beautifully. The problems only come in because everyone's network setup is just a little bit different.

It sounds like your MSDTC service might not be enabled on your client machine or, perhaps, your server.

Here's a guide to enabling it on Windows 7: --> http://www.thereforesystems.com/turn-on-msdtc-windows-7/

You will also need to enable it on your DB server: --> http://support.microsoft.com/kb/817064

An easy way to test if it works without having to contact your server admins is to set up two different local databases on your dev box. Then try to maintain a transaction across both database connections. Assuming you configured msdtc correctly, everything should work fine.

One last point is that you could look into making your life a little bit easier by referencing the System.Transactions library and using your transaction code like this:

using (TransactionScope scope = new TransactionScope())
{
    /* Perform transactional work here */
    SomeMethod();
    scope.Complete();
}

Note that no explicit rollback is required. If anything crashes inside the using statement, or if you exit the using statement before hitting .Complete();, your transaction will roll back. For more information on TransactionScope, see here: --> http://msdn.microsoft.com/en-us/library/ms172152(VS.90).aspx

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