views:

1032

answers:

1

I'm seeing a problem in a unit test where Oracle is thrown an exception with the message "Unable to enlist in a distributed transaction". We're using ODP.net and NHibernate. The issue comes up after making a certain number of commits to the database inside nested transactions. Annoyingly, this is failing on the continuous integration server (Windows Server 2003 R2 SP1), and not on my dev machine (XP SP2).

This is a small(ish) repro of the issue:

using (new TransactionScope())
{
 for (int j = 0; j < 15; j++)
 {
  using (var transactionScope = new TransactionScope(TransactionScopeOption.Required))
  using (var session = sessionFactory.OpenSession())
  {
   for (int i = 0; i < 200; i++)
   {
    var obj = [create new NHibernate mapped obj]
    session.Save(obj);
   }
   session.Flush();
   transactionScope.Complete();
  }
 }
}

The connection string we're using is:

Data Source=server;User Id=user;Password=password;Enlist=true;

Obviously this looks like a heavy handed thing to be doing, but the case of the product code is more complex (the outer transaction loop and inner transaction loop are very separated).

On the build server, it reliably bombs out on the fifth iteration of the outer loop (j). Seeing as it passes on my local machine, I'm wondering if this is hitting some kind of configured limit of transactions or connections?

Anyone got any hunches I can try out? The obvious way to fix it is to change the code to better handle this situation, but I'd just like to understand why it works on one machine and not on another. Thanks!

+2  A: 

It seems to me this has to do with your Oracle database configuration.

  • Do you use the same database server in both environments (I assume not) ?
  • Which version of the database do you use (I'll take 10g) ?

Here is what I could find based on these assumptions :

Mac
Version numbers are in the comment above. I'm connecting to the same database server when running the tests on my dev machine and when running on the build machine.The maxfree parameter is the same between my dev box and the build machine, so I don't think it's causing the issue. Thanks for the links, I'm going to try enabling the Oracle MTS tracing.
Niall Connaughton
The error appearing in the trace is: enlistInMSDTCTxn() - error enlisting 0x8004d00e. I'm having a dig about this error number and might have a look at MSDTC tracing as well.
Niall Connaughton