"本次交易已是或隐式地提交或中止"在交易范围 [英] "The transaction has already been implicitly or explicitly committed or aborted" in transaction scope

查看:176
本文介绍了"本次交易已是或隐式地提交或中止"在交易范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web服务器,并在两个不同网络的两个数据库服务器,DB1和DB2(远程数据库)。

  • 在DB1:SQL Server 2008 R2中,操作系统:Windows Server 2003的SP2
  • DB2:SQL Server 2000中,操作系统:Windows Server 2003 R2中
  • Web服务器:在Windows Server 2003 R2

我要插入这些数据库中两个不同的记录和我使用的是的TransactionScope

 使用(TransactionScope的tscope =新的TransactionScope(TransactionScopeOption.RequiresNew))
{
    //打开连接DB 1
    //插入DB1

    //打开连接DB2  - 问题就在这里
    //插入到DB2

    tscope.Complete();
}
 

当我跟踪源$ C ​​$ C,在第一DATABSE插入成功完成,但是当第二连接要被打开我遇到下面错误

错误:

  

本次交易已经或隐式地提交或中止。

我已经配置MSDTC,Distributrd事务协调器和每一件事情是确定的。我可以在我的DB服务器分发了交易,我没有问题。有什么不对的TransactionScope ?请帮我。

第一个连接的LINQ to SQL:

  DataClassesDataContext的DAC =新DataClassesDataContext();
Dac.Connection.ConnectionString = ConfigurationManager.ConnectionStrings [ConnectionCs]的ConnectionString。
tbl_KargahDistribution车间=新tbl_KargahDistribution();
Workshop.Wp code = Bodu.W preAL code;
Workshop.State = Bodu.BduState;
Workshop.City = Bodu.BduCity;
Workshop.Town = Bodu.BduTown;
Workshop.SubSystem = Bodu.BduSubSystem;
Dac.tbl_KargahDistributions.InsertOnSubmit(车间);
Dac.SubmitChanges();
 

第二个连接是:

 查询曲=新的查询();
SqlCon =新的SqlConnection(BoBaz.BazConnectionString);
SqlCon.Open();
串平方= Qu.InsertWorkshopBaseInfo();
SqlCom =新的SqlCommand(SQ,SqlCon);
 

解决方案

  Dac.SubmitChanges();
 

原因

  

本次交易已经或隐式地提交或中止。

请参阅如何使用交易带的datacontext

I have a web server and two DB servers on two different networks, Db1 and Db2(Remote Database).

  • DB1: SQL Server 2008 R2, operating system: Windows Server 2003 SP2
  • DB2: SQL Server 2000, operating system: Windows Server 2003 R2
  • Web server: Windows Server 2003 R2

I want to insert two different records in these databases and I'm using a TransactionScope.

using (TransactionScope tscope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
    //open connection db 1
    //insert into db1

    //open connection db2 -- the problem is here
    //insert into db2

    tscope.Complete();
}

When I trace the source code, inserting in the first databse is done successfully but when the second connection wants to be opened I encounter below error.

Error:

The transaction has already been implicitly or explicitly committed or aborted.

I have configured MSDTC, Distributrd transaction coordinator and every thing is ok. I can have distributed transaction in My DB server and I have no problem. What's wrong with TransactionScope? Please help me.

the first connection is LINQ TO SQL:

DataClassesDataContext Dac = new DataClassesDataContext();
Dac.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionCs"].ConnectionString;
tbl_KargahDistribution Workshop = new tbl_KargahDistribution();
Workshop.WpCode = Bodu.WpRealCode;
Workshop.State = Bodu.BduState;
Workshop.City = Bodu.BduCity;
Workshop.Town = Bodu.BduTown;
Workshop.SubSystem = Bodu.BduSubSystem;
Dac.tbl_KargahDistributions.InsertOnSubmit(Workshop);
Dac.SubmitChanges();

the second connection is:

Queries Qu = new Queries();
SqlCon = new SqlConnection(BoBaz.BazConnectionString);
SqlCon.Open();
string sq = Qu.InsertWorkshopBaseInfo();
SqlCom = new SqlCommand(sq, SqlCon);

解决方案

Dac.SubmitChanges();

causes

The transaction has already been implicitly or explicitly committed or aborted.

See How to use transactions with a datacontext

这篇关于"本次交易已是或隐式地提交或中止"在交易范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆