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.

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...