0

我们正在运行分布式事务,在极少数情况下我们会收到以下错误:

System.ObjectDisposedException:无法访问已处置的对象。对象名称:“SqlDelegatedTransaction”。在 System.Data.SqlClient.SqlDelegatedTransaction.Rollback(SinglePhaseEnlistment enlistment) 在 System.Transactions.TransactionStateDelegatedAborting.EnterState(InternalTransaction tx) 在 System.Transactions.Transaction.Rollback() 在 System.Transactions.TransactionScope.InternalDispose() 在 System.Transactions .TransactionScope.Dispose()

当 TransactionScope 超出范围并且尚未在范围内调用 Complete() 时会发生错误。预期的行为将是事务以静默方式回滚。事务没有提交,所以我们不会在数据库中得到任何损坏的数据。另一方面,我还可以提到我们正在使用 nhibernate。程序流程如下:

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

这可能在几个月内发生了一两次,所以我们并没有一直看到这种情况,一旦发生,我们就无法重现它。我们可以对服务执行具有相同值的相同命令,它会按预期工作。

4

1 回答 1

1

NHibernate 中的 TransactionScope 存在一些尚未解决的线程问题。您的问题可能与以下之一相符: https ://nhibernate.jira.com/secure/IssueNavigator.jspa?reset=true&jqlQuery=project+%3D+NH+AND+labels+%3D+TransactionScope

于 2012-10-31T13:04:57.743 回答