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);