针对 Sql Server 2000 的 TransactionScope 错误 - 合作伙伴事务管理器已禁用其对远程/网络事务的支持
我正在尝试为我的 Sql 2000 数据库的 Linq-to-Sql 操作设置一个简单的事务。 使用 TransactionScope 时,它看起来像这样:
using (TransactionScope transaction = new TransactionScope())
{
try
{
Store.DBDataContext dc = new Store.DBDataContext();
Store.Product product = GetProduct("foo");
dc.InsertOnSubmit(product);
dc.SubmitChanges();
transaction.Complete();
}
catch (Exception ex)
{
throw ex;
}
}
但是,我不断收到以下错误:
合作伙伴事务管理器已禁用其对远程/网络事务的支持。 (HRESULT 异常:0x8004D025)
但是,如果我使用传统事务设置事务,它就可以正常工作。 所以这工作得很好:
Store.DBDataContext dc = new Store.DBDataContext();
try
{
dc.Connection.Open();
dc.Transaction = dc.Connection.BeginTransaction();
Store.Product product = GetProduct("foo");
dc.InsertOnSubmit(product);
dc.SubmitChanges();
dc.Transaction.Commit();
}
catch (Exception ex)
{
dc.Transaction.Rollback();
throw ex;
}
finally
{
dc.Connection.Close();
dc.Transaction = null;
}
我想知道 TransactionScope 是否在幕后做一些与我的第二个实现不同的事情。 如果不是,不使用 TransactionScope 我会损失什么? 此外,任何有关导致错误的原因的指导也很好。 我已确认 MSDTC 正在 sql server 和我的客户端计算机上运行。
I am trying to set up a simple transaction for my Linq-to-Sql actions against my Sql 2000 database. Using TransactionScope it looks like this:
using (TransactionScope transaction = new TransactionScope())
{
try
{
Store.DBDataContext dc = new Store.DBDataContext();
Store.Product product = GetProduct("foo");
dc.InsertOnSubmit(product);
dc.SubmitChanges();
transaction.Complete();
}
catch (Exception ex)
{
throw ex;
}
}
However, i keep getting the following error:
The partner transaction manager has disabled its support for remote/network transactions. (Exception from HRESULT: 0x8004D025)
But, if I set up the transaction using a traditional transaction, it works fine. So this works fine:
Store.DBDataContext dc = new Store.DBDataContext();
try
{
dc.Connection.Open();
dc.Transaction = dc.Connection.BeginTransaction();
Store.Product product = GetProduct("foo");
dc.InsertOnSubmit(product);
dc.SubmitChanges();
dc.Transaction.Commit();
}
catch (Exception ex)
{
dc.Transaction.Rollback();
throw ex;
}
finally
{
dc.Connection.Close();
dc.Transaction = null;
}
I'm wondering if the TransactionScope is doing something different under the covers than my second implementation. If not, what am I losing by not using TransactionScope? Also, any guidance on what is causing the error would be good too. I've confirmed that MSDTC is running in both sql server and on my client machine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
请看这里:
使用 System.Transactions 和 Microsoft SQL Server 2000 进行快速事务
http://blogs.msdn.com/florinlazar/archive/2005 /09/29/475546.aspx
这里:
http://forums.microsoft.com/MSDN/ShowPost.aspx ?PostID=230390&SiteID=1
Take a look here:
Fast transactions with System.Transactions and Microsoft SQL Server 2000
http://blogs.msdn.com/florinlazar/archive/2005/09/29/475546.aspx
And here:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=230390&SiteID=1
Keith Sirmons 向我指出的 Florin Lazar 帖子中的 DatabaseTransactionAdapter 实现似乎可以解决问题。 这是我调用它的代码:
唯一让我不安的是我没有显式关闭连接,即使它没有在“using”语句中声明。
但弗洛林·拉扎尔表示,这是故意的。
The DatabaseTransactionAdapter implementation in the Florin Lazar post that Keith Sirmons pointed me to seems to do the trick. Here's my code that calls it:
The only thing that makes me uneasy is that I'm not explicitly closing the connection even though it's not declared within a 'using' statement.
But according to Florin Lazar, that's on purpose.
在 Windows 2008 或更高版本上启用此功能的步骤如下:
The steps to enable this on Windows 2008 or later are:
我在这里发布以下解决方案,因为经过一些搜索,这就是我登陆的地方,所以其他解决方案也可能如此。 我尝试使用 EF 6 调用存储过程,但遇到了类似的错误,因为存储过程使用了链接服务器。
无法执行该操作,因为链接服务器的 OLE DB 提供程序_无法开始分布式事务
合作伙伴事务管理器已禁用其对远程/网络事务的支持
转到 SQL Client 确实解决了我的问题,这也证实了这是 EF 的问题。
EF 模型生成的基于方法的尝试:
基于 ExecuteSqlCommand 的尝试:
使用:
该代码可以缩短,但我认为该版本对于调试和单步调试来说稍微更方便。
我不认为 Sql Client 一定是首选,但我觉得如果其他有类似问题的人通过谷歌找到这里,这至少值得分享。
I post the below solution here because after some searching this is where I landed, so other may too. I was trying to use EF 6 to call a stored procedure, but had a similar error because the stored procedure had a linked server being utilized.
The operation could not be performed because OLE DB provider _ for linked server _ was unable to begin a distributed transaction
The partner transaction manager has disabled its support for remote/network transactions
Jumping over to SQL Client did fix my issue, which also confirmed for me that it was an EF thing.
EF model generated method based attempt:
ExecuteSqlCommand based attempt:
With:
That code can be shortened, but I think that version is slightly more convenient for debugging and stepping through.
I don't believe that Sql Client is necessarily a preferred choice, but I felt this was at least worth sharing if anyone else having similar problems gets landed here by google.
更要注意的是:
- 服务器配置指南
启用网络 COM+ 访问 (Windows Server 2003)
开始==> 控制面板==> 添加或删除程序==>添加/删除Windows 组件,选择应用程序服务器,然后单击详细信息。 单击“启用网络 COM+ 访问”,然后单击“确定”。 单击“下一步”,然后单击“完成”。
- 如果两台服务器之间有防火墙,请为此范围端口上的输入/输出打开防火墙:
点击开始==> 控制面板==> 管理工具==> 组件服务。 展开组件服务,展开计算机,右键单击我的电脑并选择属性。
在“我的电脑属性”窗口中,单击“默认协议”选项卡,单击“面向连接的 TCP/IP”并选择属性。 在新窗口中,单击“添加”并输入新的 DTC 端口范围。
单击“确定”应用这些更改。
必须重新启动服务器才能使新更改生效
more notice that:
- Server Configuration Guide
Enable network COM+ access (Windows Server 2003)
Start ==> Control Panel ==> Add or Remove Programs ==>Add/Remove Windows Components, Select Application Server, and then click Details. Click Enable network COM+ access, and then click OK. Click Next, and then click Finish.
- If between 2 server have firewall, open firewall for both in/out on this range port:
Click Start ==> Control Panels ==> Administrative Tools ==> Component Services. Expand Component service, expand Computers, Right click on My Computer and choose Properties.
In the My Computer Properties window, click on tab Default Protocol, click on connection-oriented TCP/IP and choose properties. in the new window, click add and type new DTC ports range.
Click on OK to apply these change.
Server must be restart for new change take effect