Using ODBC on Linux to connect to MS SQL Server

Jay Miller jaymiller at
Mon Aug 7 14:37:24 EDT 2000

I am new to this list, so forgive me if this has been answered before.

Has anyone successfully used the FreeTDS ODBC driver under Linux or any
other Unix based system to connect to MS SQL?  I have gotten as far as
seeing "Connection refused", which is progress over the "Network
unreachable" that I got before setting the SYBASE environment variable.

I have iODBC 2.50.3 which I am using successfully to connect to MySQL.
Linux kernel version 2.0.x.

Our server is MS SQL Server 2000, running on Windows 2000.  I don't actually
know if it uses TDS 7.0 or not.  I think that the MS ODBC drivers from
version 7 work with 2000, so I assume the protocol is the same, or at least
backward compatable.

I have installed FreeTDS as follows:

./configure --with-tdsver=70 --enable-msdblib
make install
export SYBASE

My odbc.ini entry is:

[ODBC Data Sources]
accounting = MS SQL Accounting

Trace   = ON
Tracefile = stderr
Driver  = /usr/local/freetds/lib/
Server  = <IP Address of server>
Host    = <IP Address of server>
ServerType = SQLServer 7
USER    = Employee
PASSWORD = <password>
DATABASE = Accounting
PORT    = 1433
DSN     = accounting

My interfaces file entry is:

        query tcp ether <IP Address of server> 1433
        master tcp ether <IP Address of server> 1433

At this point, I test with iODBC's odbctest program.  Here is the output:

OpenLink ODBC Demonstration program
This program shows an interactive SQL processor

Enter ODBC connect string (? shows list): DSN=accounting

SQLAllocEnv ( ... )

SQLAllocConnect ( ... )

SQLDriverConnect ( ... )
connect: Connection refused

SQLGetInfo ( ... )

SQLGetInfo ( ... )

SQLAllocStmt ( ... )

The SQL Server IS running on port 1433.  I have it configured to log failed
login attempts, but no failed attempts appear in the log (failed attempts DO
appear when I test with a bad password from a Windows ODBC).

I was able to successfully run src/tds/unittests/t0001 and t0002 after
adding the following lines to the code:

   tds_set_port(login, 1433);
   tds_set_version(login, 7, 0);

For t0002 I also had to hard code the strings (I haven't tried to debug the
routine that reads PWD).  Output from t0002 is:

col 0 is Accounting
col 1 is Employee
tds okay on t0002.c

Curiously, if I leave the "tds_set_port" out, I get a "Connection Refused"
error.  Any help on this matter would be appreciated.

Jay Miller
Socket Internet Services
Columbia, MO, US

More information about the FreeTDS mailing list