加入收藏 | 设为首页 | 会员中心 | 我要投稿 武汉站长网 (https://www.027zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

linq-to-sql – 针对Sql Server 2000的TransactionScope错误 –

发布时间:2021-02-05 16:48:25 所属栏目:MsSql教程 来源:网络整理
导读:我正在尝试针对我的Sql 2000数据库为我的Linq-to-Sql操作设置一个简单的事务.使用TransactionScope它看起来像这样: using (TransactionScope transaction = new TransactionScope()){ try { Store.DBDataContext dc = new Store.DBDataContext(); Store.P

我正在尝试针对我的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.

(编辑:武汉站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读