DTS transaction fails: Can not access a disposed object

谁说胖子不能爱 提交于 2019-12-13 04:28:07

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/13156002/dts-transaction-fails-can-not-access-a-disposed-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!