FreeTDS is a set of libraries that, when combined with the UnixODBC driver, allows your Linux server and applications to natively talk to a Microsoft SQL Server.

To install FreeTDS and UnixODBC on CentOS, use the following script:

Run this script as root.

#!/bin/bash

export SQL_SERVER_ADDRESS="10.0.0.100"
export DATABASE_NAME="mydatabase"

#DSN = Data Source Name. This is a reference name, and can be set to any label you wish.
export MY_DSN="server-dsn"

yum install unixODBC unixODBC-devel -y
cd /tmp

wget ftp://ftp.astron.com/pub/freetds/stable/freetds-stable.tgz
tar zxvf freetds-stable.tgz

cd freetds-*
./configure --prefix=/usr --sysconfdir=/etc --with-tdsver=0.91 --enable-msdblib
make
make install

cat <<EOF >> /etc/odbc.ini
[$MY_DSN]
Driver = FreeTDS
Description = Microsoft SQL
Server = $SQL_SERVER_ADDRESS
Port = 1433
Database = $DATABASE_NAME
TDS_Version = 8.0
EOF

cat <<EOF >> /etc/odbcinst.ini
[FreeTDS]
Description     = FreeTDS unixODBC Driver
Driver          = /usr/lib/libtdsodbc.so
Setup           = /usr/lib/libtdsodbc.so
EOF

cat <<EOF >> /etc/freetds.conf
[$MY_DSN]
        host = $SQL_SERVER_ADDRESS
        port = 1433
        tds version = 8.0
EOF

To test out your install afterwards, run the following commands:

# tsql -S $MY_DSN -U database_user_name -P database_password
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1>

# isql $MY_DSN database_user_name database_password
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL>