Easysoft ODBC-ODBC Bridge

How do I find out why an ODBC call is failing?

Last Reviewed:
8th January 2024

The best why to discover the problem is to call SQLError or SQLGetDiagRec with the same handle used in the ODBC SQL API call. These functions return a status and error text which may used to identify the problem.

A small C example is:

 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;
   charstate [7];
   SQLCHARtext [1024];
   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);

This will print the error diagnostic for the last call using a connection handle which may look like this:

error: IM002:1:0:[Easysoft ODBC (Client)]
 Data source not found and no default driver specified

The state value (IM002) may be looked up against the function to find out why it failed.

You may retrieve error diagnostics from Perl DBI, PHP , mxODBC and other ODBC interfaces in a similar way.

Applies To

Knowledge Base Feedback

* Did this content help you?
* Please select one option based on your first choice:

(* Required Fields)