[freetds] Unable to connect to data source

Frederik Teerlinck largowww at gmail.com
Thu Sep 28 03:17:41 EDT 2006


Well I thought my connection problem was solved, but it isn't. I still want
to connect from my C++ program on linux to an SQL server database.

Here's a part of my code:
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);

-> this all returns ok

ret = SQLDriverConnect(connection, NULL, (SQLCHAR *)
"DSN=MYDBNAME;UID=MYUID;PWD=MYPWD", SQL_NTS,
outConnectionString, 1024, &len, SQL_DRIVER_NOPROMPT);

-> This returns SQL_ERROR. If I get more information with SQLGetDiagRec,
this gives me:
[FreeTDS][SQL Server]Unable to connect to data source

Both:
isql MYDBNAME MYUID MYPWD
tsql -S MYDBNAME -U MYUID -P MYPWD
are working as perfect, so I think my configuration of freetds and the odbc
driver should be ok.

This is my configuration:
::::::::::::::
odbc.ini
::::::::::::::
[MYDBNAME]
Driver          = TDS
Description     = ODBC connection via FreeTDS
Trace           = No
Servername      = MYDBNAME


::::::::::::::
odbcinst.ini
::::::::::::::
[TDS]
Description             = FreeTDS
Driver          = /usr/lib/odbc/libtdsodbc.so
Setup           = /usr/lib/odbc/libtdsS.so
FileUsage               = 1


In freetds.conf I have:

[MYDBNAME]
host = my.server.ip.address
port = 11433
tds version = 8.0


I've tried to change the parameters in SQLDriverConnect (adding the port,
driver, database, ...), but I always get the same result.

Anybody an idea why I can't make a connection?



More information about the FreeTDS mailing list