I can't seem to successfully open >1 DB connections via ODBC, to PostgreSQL, under Fedora. It seems to seg fault in the oddest of places. This code has worked fine on RH Linux <=9. Is there something I'm supposed to enable in the odbcinst.ini file for multiple connections to work under Fedora? A small test program and my .odbc.ini file is attached. The program runs fine if you comment out the second connection. isql on the DSN also runs fine. The program runs fine on RH Linux <=9. Thanks.
#include <assert.h> #include <stdio.h> #include <sqlext.h> #include <sql.h> #define DSN "ademko" #define UID "ademko" int main(void) { char *d = DSN, *u = UID, *p = ""; SQLHANDLE env; SQLHANDLE con1, con2; SQLRETURN Ret; assert(sizeof(SQLUINTEGER) == sizeof(int)); assert(sizeof(SQLINTEGER) == sizeof(int)); assert(sizeof(SQLDOUBLE) == sizeof(double)); fprintf(stderr, "SQLAllocHandle-env\n"); Ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env); assert(Ret == SQL_SUCCESS || Ret == SQL_SUCCESS_WITH_INFO); assert(env); // needed for SQLAllocHandle of type SQL_HANDLE_DBC it seems fprintf(stderr, "SQLSetEnvAttr\n"); Ret = SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); assert(Ret == SQL_SUCCESS || Ret == SQL_SUCCESS_WITH_INFO); fprintf(stderr, "SQLAllocHandle-DB\n"); Ret = SQLAllocHandle(SQL_HANDLE_DBC, env, &con1); assert(Ret == SQL_SUCCESS || Ret == SQL_SUCCESS_WITH_INFO); assert(con1); //Ret = SQLSetConnectAttr(con1, SQL_LOGIN_TIMEOUT, (SQLPOINTER)(5), 0); //assert(Ret == SQL_SUCCESS || Ret == SQL_SUCCESS_WITH_INFO); fprintf(stderr, "SQLConnect\n"); Ret = SQLConnect(con1, (SQLCHAR*)d, SQL_NTS, (SQLCHAR*)u, SQL_NTS, (SQLCHAR*)p, SQL_NTS); fprintf(stderr, "SQLAllocHandle-DB (2)\n"); Ret = SQLAllocHandle(SQL_HANDLE_DBC, env, &con2); assert(Ret == SQL_SUCCESS || Ret == SQL_SUCCESS_WITH_INFO); assert(con2); //Ret = SQLSetConnectAttr(con2, SQL_LOGIN_TIMEOUT, (SQLPOINTER)(5), 0); //assert(Ret == SQL_SUCCESS || Ret == SQL_SUCCESS_WITH_INFO); fprintf(stderr, "SQLConnect\n"); Ret = SQLConnect(con2, (SQLCHAR*)d, SQL_NTS, (SQLCHAR*)u, SQL_NTS, (SQLCHAR*)p, SQL_NTS); fprintf(stderr, "SQLFreeHandle-db2\n"); SQLFreeHandle(SQL_HANDLE_DBC, con2); fprintf(stderr, "SQLFreeHandle-db1\n"); SQLFreeHandle(SQL_HANDLE_DBC, con1); fprintf(stderr, "SQLFreeHandle-env\n"); SQLFreeHandle(SQL_HANDLE_DBC, env); return 0; }
[ademko] Description=PostgreSQL Driver=PostgreSQL Database=ademko Servername=127.0.0.1 UserName=ademko Password= Port=5432