home :: technology :: linux :: linuxodbc

Installing ODBC on Linux

At work, we use Microsoft SQL Server and IBM AS400 databases. Here’s how I set our Linux boxes to allow them to connect to the databases through ODBC. There are seperate instructions for the Debian and Ubuntu (9.10 Karmic Koala) and Red Hat Enterprise Linux (RHEL4 and RHEL5) distributions.

ODBC connections require several layers of software to work. The bottom layer consists of the individual ODBC drivers for each database system. Our top layer is the DBI/DBD interface for Perl. In between these layers is the ODBC driver manager, which keeps track of the DSN’s and their corresponding ODBC drivers.

Packages and Software to Install

Ubuntu Version (tested on 9.10 Karmic Koala)
Debian Version (“unstable” distribution)

We use unixODBC as our ODBC driver manager. First, install unixODBC:
NOTE: Perl’s DBD::ODBC module requires the developer’s version of unixODBC, so install that one.

  # apt-get install unixodbc-dev

Finding an ODBC driver for SQL Server was a challenge, since Microsoft refuses to directly support Linux. Fortunately, freeTDS (version 0.61 or later) seems to work fine.

  # apt-get install tdsodbc freetds-bin

Debian NOTE: Originally, I installed the libsybdb3 package to get freetds. But somewhere along the road, libsybdb3 was replaced with libsybd5. When I upgraded my Debian distribution, freetds was uninstalled in the process! Hopefully, the tdsobdc package won’t suffer from name changes.

The ODBC driver to the AS400 comes directly from IBM. The best part about the IBM website is how they constantly change their links and don’t forward the old ones. They’re worse than Microsoft in that regard: http://www-03.ibm.com/systems/i/software/access/linux/downloads.html

  # apt-get install rpm
  # apt-get install alien
  # alien -i iSeriesAccess-6.1.0-1.0.x86_64.rpm
  # ln -s /opt/ibm/iSeriesAccess/lib64/libcwb* /usr/lib64

Red Hat Enterprise Linux Version

Using Red Hat, you may get a ‘Segmentation Fault’ using DBI, even though connecting to the database works fine with tsql. If this happens, try setting the following environmental variable: PERL_DL_NONLAZY = 1
Read this Usenet thread for more details

NOTE: This appears to be fixed.

We are using unixODBC as our ODBC driver manager. A version of unixODBC comes with the Red Hat installation, but we need the developer’s version in order for both Perl’s DBD::ODBC module and FreeTDS to work:

yum install unixODBC-devel

Finding an ODBC driver for SQL Server was a challenge, since Microsoft refuses to directly support Linux. Fortunately, freeTDS version 0.61 or greater seems to work fine. Under Red Hat, we needed to compile the application.

  1. Download the source code from http://www.freetds.org/
  2. Uncompress the gzipped tar file:
    # gzip -cd freetds-0.82.tgz | tar xf -
  3. Enter the freetds directory and configure, make, and install:
    # cd freetds-0.82
    # ln -s /usr/lib/libodbcinst.so.1.0.0 /usr/lib/libodbcinst.so
    # configure --with-tdsver=7.0 --with-unixodbc=/usr/
    # make
    # make install

The ODBC driver to the AS400 comes directly from IBM: http://www-03.ibm.com/systems/i/software/access/linux/index.html . Of course, I had dependency issues. The libstdc++ dependencies are relevant, but the libXm and libXp libraries aren’t needed for ODBC connections.

# rpm -Uvh iSeriesAccess-5.4.0-1.6.i386.rpm
error: Failed dependencies:
        libstdc++.so.5 is needed by iSeriesAccess-5.4.0-1.6.i386
        libstdc++.so.5(CXXABI_1.2) is needed by iSeriesAccess-5.4.0-1.6.i386
        libstdc++.so.5(GLIBCPP_3.2) is needed by iSeriesAccess-5.4.0-1.6.i386
        libstdc++.so.5(GLIBCPP_3.2.2) is needed by iSeriesAccess-5.4.0-1.6.i386
        libXm.so.3 is needed by iSeriesAccess-5.4.0-1.6.i386
        libXp.so.6 is needed by iSeriesAccess-5.4.0-1.6.i386

# yum install /usr/lib/libstdc++.so.5

# rpm -Uvh --nodeps iSeriesAccess-5.4.0-1.6.i386.rpm


  1. Add SQL Server hosts to the FreeTDS configuration file:
    /etc/freetds/freetds.conf (Ubuntu/Debian)
    /usr/local/etc/freetds.conf (Red hat)

            host =
            port = 1433
            tds version = 7.0
  2. Confirm the new drivers are in the driver config file:
    /etc/odbcinst.ini (Ubuntu/Debian and Red Hat)

    Description     = MS SQL driver
    Driver          = /usr/local/lib/libtdsodbc.so
    FileUsage       = 2
    Trace           = No       ;(=Yes if tracing using unixODBC)
    [iSeries Access ODBC Driver]
    Description     = iSeries Access for Linux ODBC Driver
    Driver          = /opt/ibm/iSeriesODBC/lib/libcwbodbc.so
    Setup           = /opt/ibm/iSeriesODBC/lib/libcwbodbc.so
    Threading       = 2
    FileUsage       = 1
  3. Add servers to the server file:
    /etc/odbc.ini (Ubuntu/Debian and Red Hat)
    /usr/local/etc/odbc.ini (Red Hat).
    Driver                  = FreeTDS
    Description             = Production MS SQL Database
    Servername              = TDSproduction
    Database                = AVC
    UID                     = content1_badsg-1
    Driver                  = iSeries Access ODBC Driver
    Description             = Production AS/400 Database
    Servername              = AS400.APPN.SNA.IBM.COM
    System                  = AS400.APPN.SNA.IBM.COM
    DefaultLibraries        = TESTMS
    UID                     = webodbc

Test the Connections

  1. Verify unixODBC setup using odbcinst:

    # odbcinst -q -d
    	[iSeries Access ODBC Driver]
    # odbcinst -q -s
  2. Test connection to FreeTDS servers using tsql.
    Note: make sure you use the server name, not the ODBC DSN, for the -S argument. See man tsql for more details.

    # tsql -STDSproduction -Usa
  3. Test connections through unixODBC:

    # isql AS400 username PASSWORD
  4. Debugging tools for connecting to AS400:

    # /opt/ibm/iSeriesODBC/bin/cwbping as400.appn.sna.ibm.com

Installing DBD::ODBC module for Perl

# cd
# perl -MCPAN -eshell
# get DBD::ODBC
# tcsh
# cd .cpan/build/DBD-ODBC-1.09
# setenv DBI_DSN dbi:ODBC:LocalServer
# setenv DBI_USER sa
# setenv DBI_PASS sa
# setenv ODBCHOME /usr
# setenv LANG en_US
# perl Makefile.PL
# make
# make test
# make install

Last Updated: Tue, 09 Mar 2010


Sergio wrote at 2007-05-24 04:41:

Perfecto manual, lo he probado y ha funcionado a la primera. Un saludo.

Brian Cline wrote at 2007-09-06 10:51:

Thank you very much for posting this. We are setting up an Ubuntu VM to run a few PHP-based sites that will talk back and forth to our AS400. This worked like a charm.

martin wrote at 2007-12-11 14:00:

had some troubles with Servername in odbc.ini. I replaced with Server = ip and worked. Thanks.

SoyLG4u wrote at 2009-09-10 11:18:

WOW, great work! Nice to be able to find someone that knows what they are talking about. Can you make this available as a download?

Edward wrote at 2010-04-18 01:24:


Andres wrote at 2010-05-14 04:24:

Thanks thanks thanks!!! Good job

Jonathan wrote at 2010-07-14 10:19:

It seems the newer version of Ubuntu do not include libstdc++5, but rather libstdc++6. So if you are getting dependency errors after running cwbping related to libstdc++.so.5, then you'll want to install the proper version of that library. I was able to find the Debian package at: http://packages.debian.org/stable/base/libstdc++5 Once you are able to install those packages on Ubuntu, the dependency issues will go away.

Thank you for this article!

Jeff wrote at 2010-07-15 11:12:

Thanks, this was really helpful.

David wrote at 2012-02-27 03:20:

Very nice and easy to follow. I had one small problem. On our debian installation the tds driver wasn't: /usr/local/lib/libtdsodbc.so but: /usr/lib/odbc/libtdsodbc.so So I had to change the odbcinst.ini. I guess this depends on the free tds packages. Otherwise perfect! Thanks.

Steve wrote at 2012-10-04 02:22:

I'll chime in with my thanks as well. I seem to need to set up a Linux-to-MS ODBC app once every few years, and it's confusing every time. This howto was refreshingly clear and accurate.

Matt wrote at 2012-12-19 12:43:

I wanted to make a note here that on CentOS 6 I also needed to install compat-libstdc++-33.x86_64 to get everything to work.

Running #ldd /opt/ibm/iSeriesAccess/lib64/libcwbodbc.so showed it was looking for libstdc++.so.5, which resulted in an error "[unixODBC][Driver Manager]Can't open lib '/opt/ibm/iSeriesAccess/lib64/libcwbodbc.so' : file not found" when I ran #isql -v AS400

Dean wrote at 2014-04-23 08:04:

Hi, just want to ask what is the equivalent folder of lib64 into a 32bit linux ubuntu?

# ln -s /opt/ibm/iSeriesAccess/lib64/libcwb* /usr/lib64


Email or URL: