[英]Unable to open connection pooling error when using ODBC with Mono on Red Hat Linux
我们正在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
使用PHP可以使ODBC正常工作!
这是Mono程序:
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 Wire Protocol驱动程序不支持连接池。 请参阅文档:
ODBC驱动程序管理器中未实现UNIX / Linux上的ODBC连接池。 相反,它是在(某些)DataDirect ODBC驱动程序中实现的。
但看起来它在.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(Stable 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
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.