DTS事务失败:无法访问已处置的对象 [英] DTS transaction fails: Can not access a disposed object

查看:140
本文介绍了DTS事务失败:无法访问已处置的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We are running distributed transactions, and on some rare occasions we get the following error:

System.ObjectDisposedException:无法访问已处置的对象. 对象名称:"SqlDelegatedTransaction".在 System.Data.SqlClient.SqlDelegatedTransaction.Rollback(SinglePhaseEnlistment 入伍) System.Transactions.TransactionStateDelegatedAborting.EnterState(InternalTransaction tx)位于System.Transactions.Transaction.Rollback()处 System.Transactions.TransactionScope.InternalDispose()在 System.Transactions.TransactionScope.Dispose()

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

当TransactionScope超出范围并且尚未在范围内调用Complete()时,将发生错误.预期的行为将是事务以静默方式回滚.事务不会提交,因此我们不会在数据库中获取任何损坏的数据.顺便说一句,我也不能提到我们正在使用nhibernate.程序流程如下:

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.

推荐答案

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

There are some threading issues with TransactionScope in NHibernate that haven't been resolved yet. Likely your issues matches one of these: https://nhibernate.jira.com/secure/IssueNavigator.jspa?reset=true&jqlQuery=project+%3D+NH+AND+labels+%3D+TransactionScope

这篇关于DTS事务失败:无法访问已处置的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆