DTS事务失败:无法访问已处置的对象

时间:2012-10-31 10:37:42

标签: c# nhibernate transactionscope distributed-transactions

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

  

System.ObjectDisposedException:无法访问已处置的对象。   对象名:'SqlDelegatedTransaction'。在   System.Data.SqlClient.SqlDelegatedTransaction.Rollback(SinglePhaseEnlistment   入伍)   System.Transactions.TransactionStateDelegatedAborting.EnterState(InternalTransaction   tx)在System.Transactions.Transaction.Rollback()at   System.Transactions.TransactionScope.InternalDispose()at   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();
        }

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

1 个答案:

答案 0 :(得分:1)

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

相关问题