gpt4 book ai didi

c# - 在 Red Hat Linux 上使用带有 Mono 的 ODBC 时无法打开连接池错误

转载 作者:太空宇宙 更新时间:2023-11-04 13:00:34 25 4
gpt4 key购买 nike

我们在 RedHat 6.5 中使用 Mono。我们正在尝试使用 ODBC 连接到本地数据库。当我们尝试连接时,我们收到一条错误消息 ERROR - 无法启用连接池。我试图通过设置 Pooling=false 来禁用池化;在连接字符串中。

完全相同的代码在 Windows 7 上运行良好。任何帮助将不胜感激。使用 PHP,我们可以毫无问题地连接到数据库。如果有任何不同的话,它是一个 Progress OpenEdge 数据库。

这是我们的设置。

odbcinst.ini 设置如下:

[Progress]                                                                      
Description = ODBC for Progress
Driver = /usr/dlc64Bit/odbc/lib/pgoe27.so
FileUsage = 1

[ODBC]
Pooling = True
Trace = Yes
TraceFile = /home/rr/progress/trace.log
UseCursorLib = 1
UsageCount = 2

odbc.ini 设置如下:

[my_progress]                                                                   
Driver=Progress
Description=Test to Progress
DatabaseName=pt
PortNumber=9003
HostName=localhost
LoginID=
Password=
APILevel=1
ConnectFunctions=YYN
CPTimeout=60
DriverODBCVer=03.60
FileUsage=0
SQLLevel=0
UsageCount=1
ArraySize=50
DefaultLongDataBuffLen=2048
DefaultIsolationLevel=REPEATABLE READ
StaticCursorLongColBuffLen=4096

ODBC 使用 PHP 工作正常!

这是单声道程序:

using System;                                                                   
using System.Data;
using System.Data.Odbc;

public class Test
{
string connectionString, sql;

public void testProgress()
{
System.Console.WriteLine("Testing Progress");
connectionString =
"DSN=my_progress;" +
"UID=root;" +
"PWD=root;" +
"Pooling=false";
sql =
"SELECT productcode, prodtype FROM pub.locations";

}
public void testConnection()
{
try
{
IDbConnection dbcon;
dbcon = new OdbcConnection(connectionString);
dbcon.Open();
IDbCommand dbcmd = dbcon.CreateCommand();
dbcmd.CommandText = sql;
IDataReader reader = dbcmd.ExecuteReader();
while(reader.Read()) {
string product = (string) reader["productcode"];

string producttype = (string) reader["prodtype"];
Console.WriteLine(product + " " + producttype);
}
// clean up
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
catch(Exception ex)
{
System.Console.WriteLine("Error: " + ex.Message);
}
}

public static void Main(string[] args)
{
Test test = new Test();
test.testProgress();
test.testConnection();
}
}

当我编译后运行程序时,出现以下错误:

错误 - 无法启用连接池

最佳答案

Progress OpenEdge 有线协议(protocol)驱动程序不支持连接池。请参阅文档:

ODBC connection pooling on UNIX/Linux is not implemented in the ODBC Driver manager. Instead it is implemented in (some of) the DataDirect ODBC drivers.

但它看起来像是在 .NET/Mono 中默认使用:

.../mono-4.2.3/external/referencesource/System.Data/System/Data/Odbc/OdbcEnvironmentHandle.cs:

 ...
//Turn on connection pooling
//Note: the env handle controls pooling. Only those connections created under that
//handle are pooled. So we have to keep it alive and not create a new environment
//for every connection.
//
retcode = UnsafeNativeMethods.SQLSetEnvAttr(
this,
ODBC32.SQL_ATTR.CONNECTION_POOLING,
ODBC32.SQL_CP_ONE_PER_HENV,
ODBC32.SQL_IS.INTEGER);

switch(retcode) {
case ODBC32.RetCode.SUCCESS:
case ODBC32.RetCode.SUCCESS_WITH_INFO:
break;
default:
Dispose();
throw ODBC.CantEnableConnectionpooling(retcode);
}
...

我遇到以下异常(使用根据我的环境调整的示例代码 - Linux、Ubuntu 14.04、Mono JIT 编译器版本 4.2.3(稳定版 4.2.3.4/832de4b Wed Mar 16 13:19:08 UTC 2016) ):

[ERROR] FATAL UNHANDLED EXCEPTION: 
System.InvalidOperationException: ERROR - unable to enable connection pooling...
----->>> at System.Data.Odbc.OdbcEnvironmentHandle <<-----..ctor () <0x411a0b80 + 0x00097> in <filename unknown>:0
--------------------------------------
at System.Data.Odbc.OdbcEnvironment.GetGlobalEnvironmentHandle () <0x411a05c0 + 0x000bf> in <filename unknown>:0
...

关于c# - 在 Red Hat Linux 上使用带有 Mono 的 ODBC 时无法打开连接池错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34009019/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com