oracle 无法加入 NHibernate 的分布式事务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1012147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 18:25:38  来源:igfitidea点击:

Unable to enlist in a distributed transaction with NHibernate

c#oraclenhibernatetransactions

提问by Niall Connaughton

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).

我在单元测试中看到一个问题,其中 Oracle 抛出异常并显示消息“无法加入分布式事务”。我们正在使用 ODP.net 和 NHibernate。在对嵌套事务中的数据库进行一定数量的提交后,问题就出现了。令人讨厌的是,这是在持续集成服务器(Windows Server 2003 R2 SP1)上失败的,而不是在我的开发机器(XP SP2)上。

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

这是该问题的一个小(ish)重现:

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;

数据源=服务器;用户 ID=用户;密码=密码;登记=真;

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?

在构建服务器上,它可靠地在外循环 (j) 的第五次迭代中爆炸。看到它在我的本地机器上传递时,我想知道这是否达到了某种配置的事务或连接限制?

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!

任何人有任何预感我可以尝试?解决它的显而易见的方法是更改​​代码以更好地处理这种情况,但我只想了解为什么它可以在一台机器上运行而不是在另一台机器上运行。谢谢!

回答by Mac

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

在我看来,这与您的 Oracle 数据库配置有关。

  • 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) ?
  • 您是否在两种环境中使用相同的数据库服务器(我认为不是)?
  • 您使用哪个版本的数据库(我要 10g)?

Here is what I could find based on these assumptions :

根据这些假设,我可以找到以下内容: