I have a process that requires a rollback of all updates and inserts should there be an error during any phase. So i wanted to use the TransactionScope class to accomplish this. Here is my code:
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
{
IWE dbContext1 = null;
using (dbContext1 = new IWE())
{
dbContext1.Connection.Open();
//make some changes using the dbContext1
//Save Changes but don't discard yet
dbContext1.SaveChanges(false);
//make a call to another database
using (EPE context = new EPE())
{
//add or makes some changes
context.SaveChanges(false);
}
}
//if there were no problems above committ the transaction
if (success)
{
////if we get here things are looking good.
scope.Complete();
//accept the changes above against these connections.
dbContext1.AcceptAllChanges();
}
}
Problem is as soon as i make the call to the second connection i get the error:
"Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool."
I have checked to make sure that the MSDTC is enabled on both servers开发者_如何学Python. Or at least it appears so.
Other information: - There is no firewall between them.
- First DB server is running Windows Server 2003 R2 w/ sql 2005 - Second DB server is running Windows Server 2003 w/ sql 2000Can anyone point me in the right direction using the transaction scope w/ or w/o the use of distributed transactions?
Thanks in advance, Billy
I ended up going about this a different way after alot of time spent trying to get the Distributed transactions to work.
My solution was to just use a single connection. So I created a view on the first DB that mapped to the database table on the second DB(different server as well) that i needed to insert into. I imported that view into my entity model as well as all three stored procedure cud statements(only using insert but need all of them) and mapped them to the entity object accordingly.
After that everything work as it should under one single connection.
精彩评论