Reputation: 148
I have a Windows application that I am porting to UNIX/Linux. This application uses ODBC to connect to SQL Server. In this case, the SQL Server is running on a Windows server, but I don't think that matters.
The problem is that I need multiple connections to the server. So the application calls SQLDriverConnect() multiple times (with different connection handles). On Windows this works fine. But on Linux, the second call crashes.
My actual application tests the return values of the SQL functions, of course. But the cut down sample doesn't get any errors, so I have removed those tests.
I have cut the full application down to a 10 line program with the same results.
SQLHANDLE henv, hdbc1, hdbc2;
char connstr[] = "DRIVER={ODBC Driver 11 for SQL Server};<other necessary params>";
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, 0);
SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1);
SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc2);
SQLDriverConnect(hdbc1, NULL, connstr, strlen(connstr),
NULL, 0, &need, SQL_DRIVER_NOPROMPT);
SQLDriverConnect(hdbc2, NULL, connstr, strlen(connstr),
NULL, 0, &need, SQL_DRIVER_NOPROMPT);
I am hoping that the second call succeeds (or at least returns an error). Instead, the application crashes, hard, with a "Memory fault". If I debug the program using gdb, I get a little more information:
Program received signal SIGSEGV, Segmentation fault. 0x0000000000000000 in ?? ()
You may wonder why I need multiple connections to the server. In fact, I may not, but this is they way the application is currently written. If I could set some flags using ODBC calls to get multiple result sets from a single connection, then I would do that. But I have not had luck with that feature.
Many thanks
Upvotes: 0
Views: 502
Reputation: 148
This seems to be due to the ODBC driver manager I am using. There are multiple installed on the machine I am working on. If I set up a different ODBC driver manager, everything works as desired.
The failing ODBC driver manager is a home-built version of unixODBC. The successful ODBC driver manager is the native Red Hat Linux version (whatever that is). Whether this is a fault of unixODBC, or a fault of our particular build, or something else, I don't know. But I do know that my sample program works, and my full application works, when using the Red Hat version of the ODBC driver manager.
Upvotes: 1