IfxConnection 和线程可以相处吗?

发布于 2024-08-25 04:08:25 字数 2273 浏览 6 评论 0原文

我们有一个使用 IBM Informix 驱动程序的应用程序。每当我们尝试并行打开连接时,我们就会开始遇到一些非常奇怪的错误。

这是我能想到的最小的重现代码:

const int Count = 10;
const string ConnectionString = "Host=the_host;Service=the_service;Server=the_server;Database=the_database;User ID=the_user_id;Password=the_password";

static void Main()
{
    var threads = new Thread[Count];
    for (var i = 0; i < threads.Length; i++)
    {
        threads[i] = new Thread(
            number =>
            {
                using (var conn = new IfxConnection(ConnectionString))
                {
                    Console.WriteLine("Opening connection {0}... ", number);
                    try
                    {
                        conn.Open();
                        Console.WriteLine("Opened connection {0}", number);
                        var setLockCommand = conn.CreateCommand();
                        setLockCommand.CommandText = "set lock mode to wait 10;";
                        setLockCommand.ExecuteNonQuery();
                        Console.WriteLine("Releasing connection {0}", number);
                    }
                    catch (IfxException ex)
                    {
                        Console.WriteLine("Failed opening connection {0}: {1}", number, ex);
                    }
                }
            });
        threads[i].Start(i);
    }
    foreach (var thread in threads)
        thread.Join();
}

根据我们运行它的机器,我们必须稍微调整一下 Count 值才能使其失败,但 10 似乎会重现该错误始终如一。

当然,这不是生产代码,也不是我们处理线程的方式,但它在不引入任何其他变量的情况下突出了这个问题。

这是异常堆栈跟踪:

IBM.Data.Informix.IfxException: ERROR [HY000] [Informix .NET provider]General error.
   at IBM.Data.Informix.IfxConnection.GetConnectAttr(SQL_ATTR attribute, HANDLER handler)
   at IBM.Data.Informix.IfxConnection.ConnectionIsAlive()
   at IBM.Data.Informix.IfxConnectionPool.BindNodeToConnection(IfxConnPoolNode poolNode, IfxConnection connection, ConnectionPoolType ConnPoolType)
   at IBM.Data.Informix.IfxConnectionPool.Open(IfxConnection connection)
   at IBM.Data.Informix.IfxConnPoolManager.Open(IfxConnection connection)
   at IBM.Data.Informix.IfxConnection.Open()

IBM.Data.Informix.dll 版本是 3.00.06000.2。

这是在 Windows 7(32 和 64 位)和 2008(64 位)上进行测试的。

We have an application using the IBM Informix driver. Whenever we try to open connections in parallel, we start getting some really weird errors.

This is the smallest reproduction code I could come up with:

const int Count = 10;
const string ConnectionString = "Host=the_host;Service=the_service;Server=the_server;Database=the_database;User ID=the_user_id;Password=the_password";

static void Main()
{
    var threads = new Thread[Count];
    for (var i = 0; i < threads.Length; i++)
    {
        threads[i] = new Thread(
            number =>
            {
                using (var conn = new IfxConnection(ConnectionString))
                {
                    Console.WriteLine("Opening connection {0}... ", number);
                    try
                    {
                        conn.Open();
                        Console.WriteLine("Opened connection {0}", number);
                        var setLockCommand = conn.CreateCommand();
                        setLockCommand.CommandText = "set lock mode to wait 10;";
                        setLockCommand.ExecuteNonQuery();
                        Console.WriteLine("Releasing connection {0}", number);
                    }
                    catch (IfxException ex)
                    {
                        Console.WriteLine("Failed opening connection {0}: {1}", number, ex);
                    }
                }
            });
        threads[i].Start(i);
    }
    foreach (var thread in threads)
        thread.Join();
}

Depending on which machine we run it on, we had to play a little with the Count value to make it fail, but 10 seems to reproduce the error consistently.

Of course this is not production code, nor how we handle threading, but it highlights the issue without introducting any other variables.

This is the exception stack trace:

IBM.Data.Informix.IfxException: ERROR [HY000] [Informix .NET provider]General error.
   at IBM.Data.Informix.IfxConnection.GetConnectAttr(SQL_ATTR attribute, HANDLER handler)
   at IBM.Data.Informix.IfxConnection.ConnectionIsAlive()
   at IBM.Data.Informix.IfxConnectionPool.BindNodeToConnection(IfxConnPoolNode poolNode, IfxConnection connection, ConnectionPoolType ConnPoolType)
   at IBM.Data.Informix.IfxConnectionPool.Open(IfxConnection connection)
   at IBM.Data.Informix.IfxConnPoolManager.Open(IfxConnection connection)
   at IBM.Data.Informix.IfxConnection.Open()

IBM.Data.Informix.dll version is 3.00.06000.2.

This was tested on Windows 7 (32 and 64 bits) and 2008 (64 bits).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一瞬间的火花 2024-09-01 04:08:25

我解决了这个问题,在连接字符串上添加了“Pooling=false”。

const string ConnectionString = "Host=the_host;Service=the_service;Server=the_server;Database=the_database;User ID=the_user_id;Password=the_password;Pooling=false";

I solved this issue adding a "Pooling=false" on the connection string.

const string ConnectionString = "Host=the_host;Service=the_service;Server=the_server;Database=the_database;User ID=the_user_id;Password=the_password;Pooling=false";
颜漓半夏 2024-09-01 04:08:25

我在内部询问了这个问题,并得到了有关 IBM Informix ClientSDK .NET 提供程序的以下反馈:

  1. 在我们的 Windows XP 32 位开发计算机上无法重现该问题。
  2. 用户/客户尝试在 Windows 7 上运行应用程序。CSDK 3.00 未在 Windows 7 上经过认证(而且永远也不会经过认证)。
  3. 客户应升级到最新版本:CSDK 3.50.TC6(32 位)或 3.50.FC6(64 位)。这是支持。请注意,CSDK 3.50.xC5 及更早版本的修复包不支持 Windows 7。

Informix.NET 提供程序也称为 CSDK .NET 提供程序。它仍然是大多数 IDS 客户使用的首选 .NET 提供程序。 “最新的”IBM Common.NET 提供程序(它使用 DRDA 协议与 DB2 以及 IDS 配合使用,而不是 CSDK .NET 提供程序使用的 SQLI 协议)绝对是未来的策略,但很少有客户真正使用 Common。 NET 用于 IDS 应用程序开发。


由于我没有制定答案,因此我将其设为社区 Wiki。

I asked about this internally, and got the following feedback about the IBM Informix ClientSDK .NET provider:

  1. The issue is not reproducible on our Windows XP 32-bit development machine.
  2. The user/customer is trying to run the application on Windows 7. CSDK 3.00 is NOT certified on Windows 7 (and never will be).
  3. The customer should upgrade to the latest version, CSDK 3.50.TC6 (32-bit) or 3.50.FC6 (64-bit). That is supported. Note that CSDK 3.50.xC5 and earlier fix packs do not support Windows 7.

The Informix.NET provider is also referred to as CSDK .NET provider. It is still the preferred .NET provider used by the majority of IDS customers. The 'latest' IBM Common.NET provider (which works with DB2 as well as IDS using the DRDA protocol, instead of the SQLI protocol used by the CSDK .NET provider) is definitely the future strategy, but few customers are actually using Common.NET for IDS application development.


Since I didn't develop the answer, I've made it Community Wiki.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文