gpt4 book ai didi

Nhibernate出现TransactionScope错误-DTC事务预准备阶段失败-升级到Nhibernate 3.0

转载 作者:行者123 更新时间:2023-12-03 09:52:25 30 4
gpt4 key购买 nike

在事务Scope.Eg中使用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内,并且Iam收到的错误如下所示,

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)

最佳答案

尝试
Configuration.SetProperty(Environment.TransactionStrategy,"NHibernate.Transaction.AdoNetTransactionFactory")
或在nhibernate配置中

<property name="transaction.factory_class">
NHibernate.Transaction.AdoNetTransactionFactory
</property>

它对我有用=)

关于Nhibernate出现TransactionScope错误-DTC事务预准备阶段失败-升级到Nhibernate 3.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4930175/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com