[freetds] Problem with connection.

James K. Lowden jklowden at freetds.org
Tue Jan 5 20:07:07 EST 2010

Fernando wrote:
> When the app call
> it, the function return an error and the message: "FreeTDS: db-lib:
> exiting because client error handler returned 0 for msgno 20009".
> Does anyone knows what this error message mean??

It means the error handler returned 0, which is an instruction to the
library to call exit(3).  

$ grep -n INT_ include/sybdb.h
60:#define INT_EXIT     0
61:#define INT_CONTINUE 1
62:#define INT_CANCEL   2
63:#define INT_TIMEOUT  3

> /* works fine until here, then I got the error here, not even enter in
> the if statement */
> if ((dbconn = dbopen(login, DBSERVER)) == NULL)
> {
> 	fprintf(stderr, "ERROR! dbopen() page1.c.\n");
> 	return FALSE;
> }

Zero is INT_EXIT.  dbopen() never returns because when the handler returns
INT_EXIT, the library exits the program.  


The default error handler, the one you get if you don't call
dberrhandle(), usually returns INT_CANCEL, cf. default_err_handler() and
dbperror() in dblib.c.  However, Sybase's specification, which FreeTDS
conforms to, says that the default handler "will abort the program if the
error has made the affected DBPROCESS unusable".  That's what FreeTDS does
if it was compiled with enable-msdblib=no (the default case).  

See also

In your case, dbopen() failed to connect to the server.  It would return a
DBPROCESS of NULL, which would be unusable and for which DBDEAD() would
return true.  The default handler detects this, returns INT_EXIT, and the
library duly quits.  
The internal function dbperror() produces the message.  I feel if the
*library* is going to quit, it should write something to standard error.  

(I could be convinced to change FreeTDS to deviate from Sybase's
specification in this case.  I've always thought it was weird that
db-lib's default behavior is to print *nothing*.  But I wouldn't do it

The message 20009 is SYBECONN, meaning you couldn't connect to the server:

$ grep 20009 include/sybdb.h
#define SYBECONN        20009   /* Unable to connect socket -- SQL Server
#is unavailable or does not exist. */

A TDSDUMP log may help sorting out why not.  



More information about the FreeTDS mailing list