我们正在使用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工作正常!
以下是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();
}
}
编译后运行程序时,出现以下错误:
错误 - 无法启用连接池
答案 0 :(得分:0)
Progress OpenEdge有线协议驱动程序不支持连接池。参见文档:
ODBC驱动程序管理器中未实现UNIX / Linux上的ODBC连接池。 相反,它是在(某些)DataDirect ODBC驱动程序中实现的。
但它看起来默认使用在.NET / Mono中:
... /单4.2.3 /外部/ referencesource / 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
...