I am trying to set up a simple transaction for my Linq-to-Sql actions against my Sql 2000 database. Using TransactionScope it looks like this:
using (TransactionScope transaction = new TransactionScope())
{
try
{
Store.DBDataContext dc = new Store.DBDataContext();
Store.Product product = GetProduct("foo");
dc.InsertOnSubmit(product);
dc.SubmitChanges();
transaction.Complete();
}
catch (Exception ex)
{
throw ex;
}
}
However, i keep getting the following error:
The partner transaction manager has disabled its support for remote/network transactions. (Exception from HRESULT: 0x8004D025)
But, if I set up the transaction using a traditional transaction, it works fine. So this works fine:
Store.DBDataContext dc = new Store.DBDataContext();
try
{
dc.Connection.Open();
dc.Transaction = dc.Connection.BeginTransaction();
Store.Product product = GetProduct("foo");
dc.InsertOnSubmit(product);
dc.SubmitChanges();
dc.Transaction.Commit();
}
catch (Exception ex)
{
dc.Transaction.Rollback();
throw ex;
}
finally
{
dc.Connection.Close();
dc.Transaction = null;
}
I'm wondering if the TransactionScope is doing something different under the covers than my second implementation. If not, what am I losing by not using TransactionScope? Also, any guidance on what is causing the error would be good too. I've confirmed that MSDTC is running in both sql server and on my client machine.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…