"本次交易已是或隐式地提交或中止"在交易范围 [英] "The transaction has already been implicitly or explicitly committed or aborted" in transaction scope
问题描述
我有一个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();
原因
本次交易已经或隐式地提交或中止。
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屋!