unixODBC is a great utility for communicating with Microsoft SQL Server. FreeTDS ( http://www.freetds.org ) is a driver supported by unixODBC for communicating with MSSQL. In Ubuntu 14.04 both can be installed using the synaptics package manager, to successfully configure we will select the following packages for installation:

unixODBC Packages

Search for the term unixodbc in Synaptics

unixodbc
unixodbc-dev
unixodbc-bin
libodbc1
odbcinst1debian2
tdsodbc
php5-odbc
(Select all the dependencies asked to be installed along with them)

FreeTDS Packages

Search for the term freetds in Synaptics

freetds-bin
freetds-common
freetds-dev
libct4
libsybdb5

Once you have installed all these packages we need to checkout the version of FreeTDS driver that has installed on the Server.

tsql -C

Compile-time settings (established with the “configure” script)
Version: freetds v0.91
freetds.conf directory: /etc/freetds
MS db-lib source compatibility: no
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 4.2
iODBC: no
unixodbc: yes
SSPI “trusted” logins: no
Kerberos: yes

Here two parameters are of primary concern to us for configuration
1. freetds.conf directory
2. TDS Version

As shown above freetds.conf directory is /etc/freetds and our TDS Version is 4.2

Now we need to edit /etc/odbcinst.ini but before that just find out the path of the libtdsodbc.so library
It is generally installed in /usr/lib/x86_64-linux-gnu/odbc/ directory but still you can verify by issuing the follwing command on the linux terminal

find / -name libtdsodbc.so

Now open /etc/odbcinst.ini and create a new section as show below

[FreeTDS]
Description = FreeTDS Driver v0.91
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
fileusage=1
dontdlclose=1
UsageCount=1

Now open /etc/odbc.ini and create a new connection identifier

[test]
Driver = FreeTDS
Description = My Test Server
Trace = No
ServerName = mssql
Port = 1433
Database = testDB
TDS_Version = 4.2 (This version is the same as reported by tsql -C command)

Now open /etc/freetds/freetds.conf and create a new section:

[mssql]
host =
Port = 1433
tds version = 4.2

OK! we are done – Now you can test the connection by using the isql utility

isql -v test

It should connect successfully to the MSSQL server

Configure unixODBC for Ubuntu 14.04 using FreeTDS

15 thoughts on “Configure unixODBC for Ubuntu 14.04 using FreeTDS

  • June 27, 2014 at 3:50 pm
    Permalink

    Followed your instructions, still cannot connect.

    Reply
  • October 21, 2014 at 12:49 pm
    Permalink

    I am able to connect the SQL Server via tsql (tsql -v DSNname Username Password), but the command isql -v DSNname Username Password returns this error:

    [01000][unixODBC][Driver Manager]Can’t open lib ‘/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so’ : file not found
    [ISQL]ERROR: Could not SQLConnect

    The file is there:

    -rwxrwxrwx 1 root root 400608 Sep 12 2013 /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so

    Any help?

    Reply
  • December 11, 2015 at 2:20 pm
    Permalink

    If installed from source Try:
    sudo cp /usr/local/lib/libtdsodbc.so /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so

    if you ever need to find a file try:

    whereis libtdsodbc.so

    then copy it to the directory where the file is been requested.

    Reply
  • January 18, 2016 at 11:08 am
    Permalink

    when i give isql -v test {username} {password} . i am getting the following error. ” isql: error while loading shared libraries: libodbc.so.2: cannot open shared object file: No such file or directory “. I have given permission with chmod 777 to libodbc.so.2, which is in /usr/local/bin..

    What have i missed ??

    Reply
    • January 19, 2016 at 2:46 am
      Permalink

      libodbc.so.2 is a library file and ideally it should be in the library folder like ./usr/lib/x86_64-linux-gnu/libodbc.so.1
      This is the place where system looks for the libraries. You can copy the file there and run ldconfig -v to update the library cache.

      Reply
  • February 6, 2016 at 2:57 pm
    Permalink

    [S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
    [01000][unixODBC][FreeTDS][SQL Server]Unknown host machine name.
    [ISQL]ERROR: Could not SQLConnect

    Reply
    • February 6, 2016 at 3:14 pm
      Permalink

      It seems you are having DNS error or error in the host name you are providing to FreeTDS
      Please verify the host name and also verify that no firewall is blocking the port. You can use telnet to check the connectivity to the host machine and try specifying the IP instead of hostname

      Reply
      • February 6, 2016 at 3:16 pm
        Permalink

        I’m change my hostname to ipaddress but i give this error now.
        [08S01][unixODBC][FreeTDS][SQL Server]Unable to connect: Adaptive Server is unavailable or does not exist

        Reply
          • February 6, 2016 at 3:50 pm
            Permalink

            firewall is off. output like this . please help me …
            telnet 192.168.1.100 1433
            telnet: Unable to connect to remote host: Connection refused

          • February 6, 2016 at 3:53 pm
            Permalink

            Please check the server it seems that server has not opened the port on the network for the communication. Please check the network settings of the server to enable communication over the network

    • June 1, 2016 at 5:56 pm
      Permalink

      me also getting same error. Can you please tell me how you solved this problem?

      Reply
  • August 25, 2016 at 9:08 pm
    Permalink

    Please help me, i got error likes this :

    root@ubuntu1410server:/home/adminuser# isql -v mygatext sa@10.10.10.111
    [S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
    [37000][unixODBC][FreeTDS][SQL Server]Login failed for user ‘sa@10.11.1.242’.
    [ISQL]ERROR: Could not SQLConnect

    freetds.conf
    [10.10.10.111]
    host = 10.10.10.111
    port = 1433
    tds version = 4.2

    odbcinst.ini
    [FreeTDS]
    Description = FreeTDS_Driver
    Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
    Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
    fileusage=1
    dontdlclose=1
    UsageCount=1

    odbc.ini
    [mygatext]
    Driver = FreeTDS
    Description = MyTestServer
    Trace = No
    ServerName = 10.10.10.111
    Port = 1433
    Database = gatext
    TDS_Version = 4.2

    Whats must i do ? thx for yourhelp

    Reply

Leave a Reply