当我在事务范围内使用Nhibernate和ADO.Net操作时,出现了以下异常。例如,使用Nhibernate 2.1时一切正常,但现在升级到3.0会抛出错误。
using (var scope = new TransactionScope(TransactionScopeOption.Required))
{
GetmemberId(); --> NHibernate Call
Update(); ADO Call OracleDB
}
由于这是环境事务,Nhibernate试图在外部事务完成之前尽快处理事务。如果我错了,请纠正我,是否有任何解决方案可以帮助我?但是当我将Nhibernate调用移到TransactionScope之外时,一切都正常工作。我给出的示例是一个简单的示例,我的情况涉及更复杂的情况,因为我必须保持两个调用都在TransactionScope内,并且我收到的错误如下:
ERROR 13 NHibernate.Impl.AbstractSessionImpl - DTC transaction prepre phase failed System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Transaction'. at System.Transactions.Transaction.DependentClone(DependentCloneOption cloneOption) at System.Transactions.TransactionScope.SetCurrent(Transaction newCurrent) at System.Transactions.TransactionScope.PushScope() at System.Transactions.TransactionScope.Initialize(Transaction transactionToUse, TimeSpan scopeTimeout, Boolean interopModeSpecified) at System.Transactions.TransactionScope..ctor(Transaction transactionToUse) at NHibernate.Transaction.AdoNetWithDistributedTransactionFactory.DistributedTransactionContext.System.Transactions.IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment) 2011-02-08 13:41:46,033 ERROR 13 NHibernate.Impl.AbstractSessionImpl - DTC transaction prepre phase failed System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Transaction'. at System.Transactions.Transaction.DependentClone(DependentCloneOption cloneOption) at System.Transactions.TransactionScope.SetCurrent(Transaction newCurrent) at System.Transactions.TransactionScope.PushScope() at System.Transactions.TransactionScope.Initialize(Transaction transactionToUse, TimeSpan scopeTimeout, Boolean interopModeSpecified) at System.Transactions.TransactionScope..ctor(Transaction transactionToUse) at NHibernate.Transaction.AdoNetWithDistributedTransactionFactory.DistributedTransactionContext.System.Transactions.IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment)