We are running distributed transactions, and on some rare occasions we get the following error:
System.ObjectDisposedException: Cannot access a disposed object. Object name: 'SqlDelegatedTransaction'. at System.Data.SqlClient.SqlDelegatedTransaction.Rollback(SinglePhaseEnlistment enlistment) at System.Transactions.TransactionStateDelegatedAborting.EnterState(InternalTransaction tx) at System.Transactions.Transaction.Rollback() at System.Transactions.TransactionScope.InternalDispose() at System.Transactions.TransactionScope.Dispose()
The error occurs when the TransactionScope goes out of scope and Complete() has not been called within the scope. The expected behaviour would be that the transaction rolls back silently. The transaction does not commit, so we don't get any corrupt data in the database. As a side not I can also mention that we are using nhibernate. The program flow is as follows:
using (var transaction = new TransactionScope())
{
using (var session = _sessionManager.OpenSession())
{
// we have to wrap the invocation with an nhibernate transaction due to a dtc bug: http://www.mail-archive.com/nhibernate-development@googlegroups.com/msg02306.html
using (ITransaction nhibernateTrans = session.Session.BeginTransaction())
{
// code altering session data goes here
nhibernateTrans.Commit();
}
}
transaction.Complete();
}
This has happened maybe one or two times in a couple of months so we are not seeing this consistently, and once it happens we are unable to reproduce it. We can execute the same command with the same values against the service and it will work as expected.