[freetds] Problem connecting to SQL server on linux

Levente Tamási (IJ/ETH) Levente.Tamasi at ericsson.com
Tue Sep 26 03:19:33 EDT 2006


Hi,

AFAIK you have to connect first (using, for instance, SQLDriverConnect),
and then you can allocate a statement handle.

Cheers,
Levi 

-----Original Message-----
From: freetds-bounces at lists.ibiblio.org [mailto:freetds-bounces at lists.ibiblio.org] On Behalf Of Frederik Teerlinck
Sent: Monday, September 25, 2006 6:21 PM
To: freetds at lists.ibiblio.org
Subject: [freetds] Problem connecting to SQL server on linux

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]; SQLSMALLINT len;
SQLHSTMT    cmd;
SQLRETURN   ret;
SQLHENV context;

ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &context);
ret = SQLSetEnvAttr   (context, SQL_ATTR_ODBC_VERSION, (void*) SQL_OV_ODBC3,
0);
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); ....
_______________________________________________
FreeTDS mailing list
FreeTDS at lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds



More information about the FreeTDS mailing list