"A transaction has already been implicitly or explicitly committed or aborted" in the transaction area

I have a web server and two database 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 into these databases, and I use 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 into the first database is successful, but when the second connection wants to be open, I encounter the error below.

Error:

The deal has already been implicitly or explicitly committed or interrupted.

I set up MSDTC, the Distributrd Transaction Coordinator, and everything is fine. I can distribute transactions on my database server and I have no problem. What happened to 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(); 

second connection:

 Queries Qu = new Queries(); SqlCon = new SqlConnection(BoBaz.BazConnectionString); SqlCon.Open(); string sq = Qu.InsertWorkshopBaseInfo(); SqlCom = new SqlCommand(sq, SqlCon); 
+4
source share
3 answers
 Dac.SubmitChanges(); 

causes

The deal has already been implicitly or explicitly committed or interrupted.

See How to use transactions with datacontext

+1
source

I configured MSDTC, the Distributrd transaction coordinator, and every thing is fine. I can distribute transactions on my database server and I have no problems.

This may be true, but with a multiprocessor DTC it is best to double check. This error is often rooted in network issues. Perhaps the database cannot interact with the web server (problems with DNS or IP change), or the client’s own firewall may block DTC (check the settings of the Windows firewall on the web server).

0
source

Did you just notice this when you go through the code?

It is possible that a transaction will pick a time and automatically roll back, because the time taken to execute the code exceeds the TransactionScope timeout limit. I think the default timeout value is 60 seconds.

0
source

Source: https://habr.com/ru/post/1379294/


All Articles