导致Windows服务在使用NHibernate结束分布式事务时崩溃的异常 [英] Exception causing windows service to crash on ending distributed transaction with NHibernate

查看:97
本文介绍了导致Windows服务在使用NHibernate结束分布式事务时崩溃的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用.NET 4.0框架编写的Windows服务,该服务在与Oracle数据库通信的分布式事务中使用NHibernate登记.在我们的测试环境中,服务遇到了数据库错误,这似乎导致NHibernate关闭ADO.NET连接时出现了问题.

I have a windows service written in the .NET 4.0 framework that uses NHibernate enlisting in a distributed transaction talking to an Oracle database. Within our test environment the service encountered an error with the database which seems to have caused a problem with NHibernate closing the ADO.NET connection.

从打开会话到处理NHibernate的整个调用都包装在try/catch块中,该块捕获System.Exception,但错误未捕获在该块中.

The entire call against NHibernate, from opening the session to disposing of it, is wrapped within a try/catch block that catches System.Exception but the error is not caught within that block.

我从下面的Windows事件日志中包括了堆栈跟踪,以供参考.

I've included the stack trace from the windows event log below for reference.

我认为该异常是在另一个线程(堆栈跟踪似乎指向该线程)中引发的,该线程随后传播并导致Windows服务崩溃.

I believe that the exception is being thrown in another thread (which the stack trace seems to refer to) which then propogates up and causes the windows service to crash.

我的问题是:
1.如果它是另一个线程,它是从哪里来的(它是从什么开始的?)?
2.有什么我可以添加到我的代码中的,以确保不会发生此异常并关闭Windows服务吗?

My questions are:
1. If it is another thread, where does it come from (what starts it)?
2. Is there anything I can add to my code to make sure this exception does not escape and bring down the windows service?

应用程序:X
框架版本:v4.0.30319
说明:由于未处理的异常,进程已终止.
异常信息:NHibernate.ADOException
堆栈:
在NHibernate.Connection.ConnectionProvider.CloseConnection(System.Data.IDbConnection)
在NHibernate.Connection.DriverConnectionProvider.CloseConnection(System.Data.IDbConnection)
在NHibernate.AdoNet.ConnectionManager.CloseConnection()
在NHibernate.AdoNet.ConnectionManager.AfterTransaction()
在NHibernate.Impl.SessionImpl.AfterTransactionCompletion(Boolean,NHibernate.ITransaction)
在NHibernate.Transaction.AdoNetWithDistributedTransactionFactory +<> c_ DisplayClass1.b _0(System.Object,System.Transactions.TransactionEventArgs)
在System.Transactions.TransactionCompletedEventHandler.Invoke处(System.Object,System.Transactions.TransactionEventArgs)
在System.Transactions.TransactionStatePromotedAborted.EnterState(System.Transactions.InternalTransaction)处
在System.Transactions.InternalTransaction.DistributedTransactionOutcome处(System.Transactions.InternalTransaction,System.Transactions.TransactionStatus)
在System.Transactions.Oletx.RealOletxTransaction.FireOutcome处(System.Transactions.TransactionStatus)
在System.Transactions.Oletx.OutcomeEnlistment.InvokeOutcomeFunction(System.Transactions.TransactionStatus)处
在System.Transactions.Oletx.OletxTransactionManager.ShimNotificationCallback(System.Object,Boolean)处
在System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(System.Object,布尔值)

Application: X
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: NHibernate.ADOException
Stack:
at NHibernate.Connection.ConnectionProvider.CloseConnection(System.Data.IDbConnection)
at NHibernate.Connection.DriverConnectionProvider.CloseConnection(System.Data.IDbConnection)
at NHibernate.AdoNet.ConnectionManager.CloseConnection()
at NHibernate.AdoNet.ConnectionManager.AfterTransaction()
at NHibernate.Impl.SessionImpl.AfterTransactionCompletion(Boolean, NHibernate.ITransaction)
at NHibernate.Transaction.AdoNetWithDistributedTransactionFactory+<>c_DisplayClass1.b_0(System.Object, System.Transactions.TransactionEventArgs)
at System.Transactions.TransactionCompletedEventHandler.Invoke(System.Object, System.Transactions.TransactionEventArgs)
at System.Transactions.TransactionStatePromotedAborted.EnterState(System.Transactions.InternalTransaction)
at System.Transactions.InternalTransaction.DistributedTransactionOutcome(System.Transactions.InternalTransaction, System.Transactions.TransactionStatus)
at System.Transactions.Oletx.RealOletxTransaction.FireOutcome(System.Transactions.TransactionStatus)
at System.Transactions.Oletx.OutcomeEnlistment.InvokeOutcomeFunction(System.Transactions.TransactionStatus)
at System.Transactions.Oletx.OletxTransactionManager.ShimNotificationCallback(System.Object, Boolean)
at System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(System.Object, Boolean)

推荐答案

如果它是另一个线程,它是从哪里来的(它是从什么开始的)?

If it is another thread, where does it come from (what starts it)?

NHibernate.Transaction.AdoNetWithDistributedTransactionFactory内部,有一个System.Transactions.Transaction.TransactionCompleted的事件处理程序.完成后,.NET框架会在线程池线程上触发此事件,如堆栈跟踪底部所示.

Inside NHibernate.Transaction.AdoNetWithDistributedTransactionFactory, there exists an event handler for System.Transactions.Transaction.TransactionCompleted. This event is fired on a thread pool thread by the .NET framework upon completion, as shown at the bottom of your stack trace.

有什么我可以添加到我的代码中的,以确保此异常不会逸出并关闭Windows服务吗?

Is there anything I can add to my code to make sure this exception does not escape and bring down the windows service?

正确的做法是准确查明异常发生的原因.我没有使用过Oracle,但是在处理DTC和SQL Server时确实没有这个特殊的问题(尽管还有很多其他问题).问题的根源可能是DTC或NHibernate中的错误.

The correct thing to do is hunt down exactly why the exception occurs. I haven't used Oracle, but didn't really have this particular issue dealing with DTC and SQL Server (though there are plenty of other ones). The source of the problem could be DTC or a bug in NHibernate.

这篇关于导致Windows服务在使用NHibernate结束分布式事务时崩溃的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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