tags:

views:

22

answers:

1

I have two IDbCommand objects that are created from an NHibernate session, and they are enlisted in a transaction via the NHibernate session. The first database command inserts a value into an Oracle global temporary table and the second command reads values from the table. With an Oracle GTT, a transaction is needed for both commands in order to preserve the data in the GTT.

The strange thing is that the second command reads values from the GTT, as expected, when it's run on one server, but the exact same code doesn't work on the other server. What's even stranger, is that the first request on the non-working server works if it happens immediately after the IIS worker processes have been recycled. Each request after that does not work - specifically, the values in the GTT are not maintained after being inserted.

ISession session = sessionFactory.GetSession();
ITransaction transaction = session.BeginTransaction();

IDbCommand cmdInsert = session.Connection.CreateCommand();
transaction.Enlist(cmdInsert);
cmdInsert.CommandText = "insert into TEMP_TABLE values (1)";
cmdInsert.ExecuteNonQuery();

IDbCommand cmdRead = session.Connection.CreateCommand();
transaction.Enlist(cmdRead);
cmdRead.CommandText = "select from TEMP_TABLE";

// Nothing is returned here after the second request
cmdRead.ExecuteQuery();

transaction.Commit();

Why would the transaction that is created from an NHibernate session not properly enlist IDbCommands after the first request to an IIS server?

A: 

We ended up using the Oracle Data Provider for .NET (ODP.NET) driver and replacing the deprecated Microsoft System.Data.OracleClient driver. This fixed the transaction support. Not sure why the deprecated driver worked on one server and not the other, but I guess it's deprecated, so I'm not going to investigate it further.

red tiger