问题描述
我们正在运行分布式事务,在极少数情况下,会出现以下错误:
We are running distributed transactions, and on some rare occasions we get the following error:
当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/[email protected]/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事务失败:无法访问已处置的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!