Informix, NHibernate, TransactionScope interaction difficulties
- by John Prideaux
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: