Call SQLError
or SQLGetDiagRec
with the same handle used in the ODBC call that failed. These functions return a status and error message that help identify the problem. For example:
ret = SQLDriverConnect(hdbc, NULL, in_connection_string, SQL_NTS, out_con_str, sizeof(out_con_str), &out_con_str_len, SQL_DRIVER_COMPLETE); if (!SQL_SUCCEEDED(ret)) { int i=0; SQLRETURN ret; charstate [7]; SQLCHARtext [1024]; SQLSMALLINT len; SQLINTEGER native; charcbuf [2048]; while(SQL_SUCCEEDED(SQLGetDiagRec(SQL_HANDLE_DBC, hdbc, ++i, state,&native, text, sizeof(text), &len))) { sprintf(cbuf, "error: %s:%d:%ld:%s\n", state, i, native, text); fprintf(stderr, cbuf); } exit(1); }
This prints the error diagnostic for the last API call. For example:
error: IM002:1:0:[Easysoft ODBC (Client)] Data source not found and no default driver specified
Look up the state value (IM002)
against the API call to find out why it failed.
You can retrieve error diagnostics from Perl DBI, PHP, mxODBC, and so on in a similar way.