I’m using the following code pattern to run some queries on a third party database using ODBC.
Everything works fine if I manually enable Connection Pooling using the ODBC Data Source Administrator.
Problem is I get an ODBC connection error on the 2nd database call if Connection Pooling is disabled.
Basically, I would like to avoid the deployment hassle of enabling connection pooling on customer computers (unless there is some easy way).
Is there something wrong with the following ODBC code?
using (var conn = GetODBCConnection())
{
using (var sdr = new OdbcCommand("SELECT * FROM [TABLE]", conn).ExecuteReader())
{
while (sdr.Read())
{
// use data
}
}
}
private OdbcConnection GetGenieConnection()
{
var conn = new OdbcConnection(_connString);
conn.Open();
return conn;
}
PS: I’m using the 4D v12 ODBC Driver. I investigated connection string options to turn on connection pooling but couldn’t find anything.
EDIT: Could this behaviour have something to do with threads? I am calling the first ODBC database call in a BackgroundWorker thread. It seems to work if I call everything in a single thread. Can this be explained?
If any other poor soul ends up here, my solution was to:
This is not an ideal solution in terms of performance but it works.