我有一个小程序试图使用 Informix .NET 提供程序将 NHibernate 插入包装到 TransactionScope 对象中的 Informix 数据库中。我收到下面指定的错误。没有 TransactionScope 对象的代码可以工作——包括当插入被包装在 NHibernate 会话事务中时。关于问题是什么的任何想法?顺便说一句,如果没有 EnterpriseServicesInterop,Informix .NET 提供程序将不会参与 TransactionScope 事务(在不涉及 NHibernate 的情况下进行验证)。
代码片段:
public static void TestTScope()
{
Employee johnp = new Employee { name = "John Prideaux" };
using (TransactionScope tscope = new TransactionScope(
TransactionScopeOption.Required,
new TransactionOptions() { Timeout = new TimeSpan(0, 1, 0),
IsolationLevel = IsolationLevel.ReadCommitted },
EnterpriseServicesInteropOption.Full))
{
using (ISession session = OpenSession())
{
session.Save(johnp);
Console.WriteLine("Saved John to the database");
}
}
Console.WriteLine("Transaction should be rolled back");
}
static ISession OpenSession()
{
if (factory == null)
{
Configuration c = new Configuration();
c.AddAssembly(Assembly.GetCallingAssembly());
factory = c.BuildSessionFactory();
}
return factory.OpenSession();
}
static ISessionFactory factory;
堆栈跟踪:
NHibernate.ADOException 未处理 Message="Could not close IBM.Data.Informix.IfxConnection connection" Source="NHibernate" StackTrace: at NHibernate.Connection.ConnectionProvider.CloseConnection(IDbConnection conn) at NHibernate.Connection.DriverConnectionProvider.CloseConnection(IDbConnection conn ) 在 NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Release() 在 NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(方言方言,IConnectionHelper connectionHelper) 在 NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory) 在 NHibernate.Impl.SessionFactoryImpl NHibernate.Cfg.Configuration 中的 ..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)。BuildSessionFactory() at HelloNHibernate.Employee.OpenSession() in D:\Development\ScratchProject\HelloNHibernate\Employee.cs:line 73 at HelloNHibernate.Employee.TestTScope() in D:\Development\ScratchProject\HelloNHibernate\Employee.cs:line 53 在 HelloNHibernate.Program.Main(String[] args) 在 D:\Development\ScratchProject\HelloNHibernate\Program.cs:第 19 行在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) 在 System.AppDomain.ExecuteAssembly (String assemblyFile, Evidence assemblySecurity, String[] args) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ThreadHelper.ThreadStart_Context(Object state) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback 回调,对象状态)在 System.Threading.ThreadHelper.ThreadStart() InnerException:IBM.Data.Informix.IfxException Message="ERROR - no error information available" Source="IBM.Data.Informix" ErrorCode=-2147467259 StackTrace:在 IBM。 Data.Informix.IfxConnection.HandleError(IntPtr hHandle, SQL_HANDLE hType, RETCODE retcode) 在 IBM.Data.Informix.IfxConnection.DisposeClose() 在 IBM.Data.Informix.IfxConnection.Close() 在 NHibernate.Connection.ConnectionProvider.CloseConnection( IDbConnection conn) 内部异常:ErrorCode=-2147467259 StackTrace:在 IBM.Data.Informix.IfxConnection.DisposeClose() 在 IBM.Data.Informix.IfxConnection.Close() 的 IBM.Data.Informix.IfxConnection.HandleError(IntPtr hHandle, SQL_HANDLE hType, RETCODE retcode)在 NHibernate.Connection.ConnectionProvider.CloseConnection(IDbConnection conn) InnerException:ErrorCode=-2147467259 StackTrace:在 IBM.Data.Informix.IfxConnection.DisposeClose() 在 IBM.Data.Informix.IfxConnection.Close() 的 IBM.Data.Informix.IfxConnection.HandleError(IntPtr hHandle, SQL_HANDLE hType, RETCODE retcode)在 NHibernate.Connection.ConnectionProvider.CloseConnection(IDbConnection conn) InnerException: