Skip to Content.
Sympa Menu

freetds - [freetds] Problem connecting to SQL server on linux

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Frederik Teerlinck" <largowww AT gmail.com>
  • To: freetds AT lists.ibiblio.org
  • Subject: [freetds] Problem connecting to SQL server on linux
  • Date: Mon, 25 Sep 2006 18:20:39 +0200

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);
....




Archive powered by MHonArc 2.6.24.

Top of Page