Informix,NHibernate,TransactionScope交互困难

时间:2010-01-22 21:13:38

标签: nhibernate informix transactionscope

我有一个小程序试图使用Informix .NET Provider将NHibernate插入包装到TransactionScope对象中的Informix数据库中。我收到下面指定的错误。没有TransactionScope对象的代码可以正常工作 - 包括插入包装在NHibernate会话事务中的时间。关于问题是什么的任何想法?顺便说一下,如果没有EnterpriseServicesInterop,Informix .NET Provider将不参与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 =“无法关闭IBM.Data.Informix.IfxConnection连接”     来源= “NHibernate的”     堆栈跟踪:          在NHibernate.Connection.ConnectionProvider.CloseConnection(IDbConnection conn)          在NHibernate.Connection.DriverConnectionProvider.CloseConnection(IDbConnection conn)          在NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Release()          at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect,IConnectionHelper connectionHelper)          在NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory)          在NHibernate.Impl.SessionFactoryImpl..ctor(配置cfg,IMapping映射,设置设置,EventListeners监听器)          在NHibernate.Cfg.Configuration.BuildSessionFactory()          在D:\ Development \ ScratchProject \ HelloNHibernate \ Employee.cs中的HelloNHibernate.Employee.OpenSession():第73行          在D:\ Development \ ScratchProject \ HelloNHibernate \ Employee.cs中的HelloNHibernate.Employee.TestTScope():第53行          在D:\ Development \ ScratchProject \ HelloNHibernate \ Program.cs中的HelloNHibernate.Program.Main(String [] args):第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(对象状态)          在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)          在System.Threading.ThreadHelper.ThreadStart()     InnerException:IBM.Data.Informix.IfxException          消息=“错误 - 没有可用的错误信息”          来源= “IBM.Data.Informix”          错误码= -2147467259          堆栈跟踪:               at IBM.Data.Informix.IfxConnection.HandleError(IntPtr hHandle,SQL_HANDLE hType,RETCODE retcode)               at IBM.Data.Informix.IfxConnection.DisposeClose()               在IBM.Data.Informix.IfxConnection.Close()               在NHibernate.Connection.ConnectionProvider.CloseConnection(IDbConnection conn)          InnerException:

2 个答案:

答案 0 :(得分:1)

在会话后创建事务时,它可能会起作用,或者使用session.begintransaction

答案 1 :(得分:1)

您的Informix数据库是否设置了日志记录?如果不是,交易根本不起作用,这是预期的行为。