以下代码片段在 SQL Server 2008 (SP1) 上运行良好,但在 Oracle 11g 上调用 session.BeginTransaction() 时会抛出异常,错误信息为“Connection is already part of a local or a distributed transaction”(堆栈跟踪如下所示)。使用 “NHibernate.Driver.OracleDataClientDriver”。是否还有其他人遇到过这个问题?
using (var scope = new TransactionScope())
{
using (var session = sessionFactory.OpenSession())
using (var transaction = session.BeginTransaction())
{
// do what you need to do with the session
transaction.Commit();
}
scope.Complete();
}
异常发生在:NHibernate.Transaction.AdoTransaction.Begin(IsolationLevel isolationLevel) NHibernate.Transaction.AdoTransaction.Begin() NHibernate.AdoNet.ConnectionManager.BeginTransaction() NHibernate.Impl.SessionImpl.BeginTransaction() MetraTech.BusinessEntity.DataAccess.Persistence.StandardRepository.SaveInstances(List`1& dataObjects) in S:\MetraTech\BusinessEntity\DataAccess\Persistence\StandardRepository.cs:line 3103
内部错误信息为:连接已经是本地或分布式事务的一部分 内部异常位于:Oracle.DataAccess.Client.OracleConnection.BeginTransaction(IsolationLevel isolationLevel) Oracle.DataAccess.Client.OracleConnection.BeginDbTransaction(IsolationLevel isolationLevel) System.Data.Common.DbConnection.System.Data.IDbConnection.BeginTransaction() NHibernate.Transaction.AdoTransaction.Begin(IsolationLevel isolationLevel)