Skip to Content.
Sympa Menu

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

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Levente Tamási (IJ/ETH) <Levente.Tamasi AT ericsson.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Problem connecting to SQL server on linux
  • Date: Tue, 26 Sep 2006 09:19:33 +0200

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




Archive powered by MHonArc 2.6.24.

Top of Page