[freetds] Problem connecting to SQL server on linux

Frederik Teerlinck largowww at gmail.com
Mon Sep 25 12:20:39 EDT 2006

I'm trying to connect to an SQL server database using freeTDS on a linux
server. I've got an example and I'm trying to use this for my program, but I
can't seem to connect to the DB (see code below). The returnvalues from
SQLAllocHandle(SQL_HANDLE_STMT, connection, &cmd) and SQLDriverConnect are
SQL_ERROR. I'm quit a newbie in this area, so I've got the feeling that I'm
missing a step here. Anybody an idea on what's going wrong here? Is there a
way I can have get information on why the returncode is an SQL_ERROR?

SQLHDBC connection;
unsigned char outConnectionString[1024];
SQLHSTMT    cmd;
SQLHENV context;

ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &context);
ret = SQLSetEnvAttr   (context, SQL_ATTR_ODBC_VERSION, (void*) SQL_OV_ODBC3,
ret = SQLAllocHandle(SQL_HANDLE_DBC, context, &connection);

ret = SQLAllocHandle(SQL_HANDLE_STMT, connection, &cmd);
ret = SQLDriverConnect(connection, NULL, (SQLCHAR *)
"DRIVER=FreeTDS;Address=<IPaddress of the SQL
server>;UID=<login>;PWD=<pwd>;DATABASE=<DBname>;port=<port>;", SQL_NTS,
outConnectionString, 1024, &len, SQL_DRIVER_NOPROMPT);

More information about the FreeTDS mailing list