[unixODBC-support] Checking connection status with ODBC
Alan J Batsford
AJBatsford at uss.com
Wed Jan 14 15:28:30 GMT 2009
unixodbc-support-bounces at mailman.unixodbc.org wrote on 01/13/2009 12:13:21
> Alan J Batsford wrote:
> > I'm using unixODBC 2.2.14 on CentOS 4.6. Right now I'm using ODBC to
> > connect to postgreSQL 8.2.5 within a C/C++ program, but the DSN is
> > going to change to Oracle soon. I can make a connection and run
> > queries. What's the best way to generically check the connection
> > Thanks for all your advise.
> You could try using SQLGetConnectAttr with SQL_ATTR_CONNECTION_DEAD.
Thanks, I tried the function out but I can't quite get it to work.
SQLGetConnectAttr is returning -1 both when the connection is down and up.
When it's down I call SQLGetDiagRec and recieve a message about the
connection being down. But when the connection is up and I try to get the
diagnostic message I get an unreadable message. For example my last test
with NativeError set to 0.
My call to SQLGetConnectionAttr:
char ODBC_str_err; // Not sure how long this needed to be.
ODBC_erg = SQLGetConnectAttr(ODBC_Connection, SQL_ATTR_CONNECTION_DEAD,
(SQLPOINTER)ODBC_str_err, sizeof (ODBC_str_err), &StringLength);
if ((ODBC_erg == SQL_SUCCESS) || (ODBC_erg == SQL_SUCCESS_WITH_INFO))
My code for checking the connection:
void print_odbc_error(SQLHDBC ODBC_Connection)
SQLINTEGER ODBC_err = 0;
SQLSMALLINT ODBC_mlen = 0;
memset (ODBC_stat, 0, sizeof (ODBC_stat));
memset (ODBC_msg, 0, sizeof (ODBC_msg));
if (ODBC_Connection== 0)
fprintf("print_odbc_error failed due to ODBC Connection Handle ==
SQLGetDiagRec(SQL_HANDLE_DBC, ODBC_Connection, 1, ODBC_stat, &ODBC_err,
ODBC_msg, sizeof(ODBC_msg), &ODBC_mlen);
fprintf("%s (%d)\n", ODBC_msg, ODBC_err);
Perhaps I'm using arguments wrong? Or the postgres ODBC driver doesnt
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the unixODBC-support