简体   繁体   中英

Unable to enlist in a distributed transaction with NHibernate

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!

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 :

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM