Informix、NHibernate、TransactionScope 交互困难

发布于 2024-08-18 20:16:44 字数 3440 浏览 7 评论 0原文

我有一个小程序,尝试使用 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() 在NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(方言方言,IConnectionHelper连接Helper) 在 NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory) 在NHibernate.Impl.SessionFactoryImpl..ctor(配置cfg,IMapping映射,Settings设置,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(程序集,String[] args) 在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile,证据 assemblySecurity,字符串 [] args) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态) 在 System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext,ContextCallback 回调,对象状态) 在 System.Threading.ThreadHelper.ThreadStart() 内部异常:IBM.Data.Informix.IfxException 消息 =“错误 - 没有可用的错误信息” 来源=“IBM.Data.Informix” 错误代码=-2147467259 堆栈跟踪: 在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) 内部异常:

I have a small program that is trying to wrap an NHibernate insert into an Informix database in a TransactionScope object using the Informix .NET Provider. I am getting the error specified below. The code without the TransactionScope object works -- including when the insert is wrapped in an NHibernate session transaction. Any ideas on what the problem is? BTW, without the EnterpriseServicesInterop, the Informix .NET Provider will not participate in a TransactionScope transaction (verified without NHibernate involved).

Code Snippet:

    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;

Stack Trace:

NHibernate.ADOException was unhandled
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)
at NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Release()
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper)
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory)
at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)
at NHibernate.Cfg.Configuration.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
at HelloNHibernate.Program.Main(String[] args) in D:\Development\ScratchProject\HelloNHibernate\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: IBM.Data.Informix.IfxException
Message="ERROR - no error information available"
Source="IBM.Data.Informix"
ErrorCode=-2147467259
StackTrace:
at IBM.Data.Informix.IfxConnection.HandleError(IntPtr hHandle, SQL_HANDLE hType, RETCODE retcode)
at IBM.Data.Informix.IfxConnection.DisposeClose()
at IBM.Data.Informix.IfxConnection.Close()
at NHibernate.Connection.ConnectionProvider.CloseConnection(IDbConnection conn)
InnerException:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终陌 2024-08-25 20:16:44

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

It will probably work when you create the transaction after the session or, use session.begintransaction

━╋う一瞬間旳綻放 2024-08-25 20:16:44

您的 Informix 数据库设置是否带有日志记录?如果不是,交易将根本无法进行,这是预期的行为。

Is your Informix Database setup with Logging? If it's not, transactions won't work at all, this is the expected behavior.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文