linq-to-sql – 针对Sql Server 2000的TransactionScope错误 – 合作伙伴事务管理器已禁用其对远程/网络事务的支持

前端之家收集整理的这篇文章主要介绍了linq-to-sql – 针对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和我的客户端机器上运行.

解决方法

看看这里:

使用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

First verify the “Distribute Transaction Coordinator” Service is
running on both database server computer and client computers
1. Go to “Administrative Tools > Services”
2. Turn on the “Distribute Transaction Coordinator” Service if it is not running

If it is running and client application is not on the same computer as
the database server,on the computer running database server
1. Go to “Administrative Tools > Component Services”
2. On the left navigation tree,go to “Component Services > Computers > My Computer” (you may need to double click and wait as some nodes
need time to expand)
3. Right click on “My Computer”,select “Properties”
4. Select “MSDTC” tab
5. Click “Security Configuration”
6. Make sure you check “Network DTC Access”,“Allow Remote Client”,
“Allow Inbound/Outbound”,“Enable TIP” (Some option may not be
necessary,have a try to get your configuration)
7. The service will restart
8. BUT YOU MAY NEED TO REBOOT YOUR SERVER IF IT STILL DOESN’T WORK
(This is the thing drove me crazy before)

On your client computer use the same above procedure to open the
“Security Configuration” setting,make sure you check “Network DTC
Access”,“Allow Inbound/Outbound” option,restart service and computer
if necessary.

On you sql server service manager,click “Service” dropdown,select “Distribute Transaction Coordinator”,it should be also running on your server computer.

原文链接:https://www.f2er.com/mssql/83772.html

猜你在找的MsSQL相关文章