iODBC Driver Manager

iODBC is one of three popular ODBC driver managers available for Unix (the others being unixODBC, and Merant which is apparently the official licensed Microsoft ODBC driver manager ported to Unix).

First, build iODBC according to the documentation or install it via RPM, DEB or other package manager.

Now build FreeTDS using the --with-iodbc flag to specify where FreeTDS can find the include files from iODBC. For instance if iODBC's header files are in /opt/libiodbc/include use /opt/libiodbc. By default the location will be /usr/local.

$ ./configure --prefix=/usr/local/freetds --with-iodbc=/usr/local
$ gmake
$ su root
Password: 
$ gmake install

In this example the FreeTDS ODBC libraries will be installed in /usr/local/freetds/lib. We need to tell the driver manager where to find them. We do so by editing $HOME/.odbc.ini or /etc/odbc.ini. A sample odbc.ini file comes with FreeTDS in the samples directory.

Example 5-2. Sample odbc.ini File

;
;  odbc.ini
;
[ODBC Data Sources]
 JDBC = Sybase JDBC Server

[JDBC]
Driver          = /usr/local/freetds/lib/libtdsodbc.so
Description     = Sybase JDBC Server
Trace           = No
Servername      = JDBC
Database        = pubs2

[Default]
Driver          = /usr/local/freetds/lib/libtdsodbc.so
Here we specified that the JDBC entry from the FreeTDS interfaces file will show on a listing of DSNs (if this is Greek to you, please consult some ODBC documentation) and tell it to use the libtdsodbc library to connect with.

iODBC comes with a sample command line query program called odbctest that is located in the iodbc/samples directory. Using this program you can get a listing of DSNs, connect, and issue queries. It is often useful to compile a program such as this directly against the FreeTDS driver instead of using a driver manager. This makes it simpler to debug if something goes wrong. To do so, simply compile and install the ODBC driver with iODBC as normal, then compile and link the program directly:

$ make odbctest.o
$ gcc -g -o odbctest odbctest.o /usr/local/freetds/lib/libtdsodbc.a
The -g is important to keep the symbol tables for debugging purposes. Now you can run gdb or another debugger and set breakpoints on functions in the library without the driver manager getting in the way.

Note: When compiling directly to FreeTDS you still must use the driver manager's header files.

New configuration methods

DSN-less and freetds.conf-less

As of version 0.61, FreeTDS supports DSN-less connections and freetds.conf-less connections.

DSN-less

No connection information is specified in odbc.ini.

freetds.conf-less

All connection information is specified in odbc.ini, without the need for freetds.conf.

To support these methods, some options were added.

Table 5-1. Connection attributes

NameDefaultMeaningPossible ValuesIn odbc.ini
DSNnoneUse DSN. This will search in odbc.ini for entry. It lets you specify a connection like SQLConnect, but using SSQLDriverConnect. Do not use Servername and DSN together. Can be specified only in a connection string, not in odbc.ini. A valid DSN entryno
ServernamenoneThis is the old "server" specification. This refers to a freetds.conf servername, not a hostname as known to DNS. If you want to use freetds.conf-less configuration, use Server instead.A valid freetds.conf server sectionyes
ServernoneThis specifies the hostname of a server. Used in freetds.conf-less configuration.A server name or (ip) addressyes
PortDepends on the TDS version specified with configureThe tcp/ip port of SQL Server.Any TCP portyes
UIDnoneCan be specified only for a DSN-less connection (for security reasons, do not store username/password in a configuration file). To use domain authentication, specify the domain using the format domain\password.Any valid usernameno
PWDemptyCan be specified only for a DSN-less connection (for security reasons, do not store username/password in a configuration file). Clear text password (use domain password for domain authentication).Anyno
TDS_VersionDepends on the TDS version specified with configureTDS protocol version to use (ie 5.0, 7.0).Any valid protocol versionyes
APPnoneApplication name.Anyyes
WSIDComputer nameCan be specified only for a DSN-less connection. Name of the local computer, sent to server.Anyno
LANGUAGEus_englishLanguage used by server.Anyyes

Example 5-3. Sample freetds.conf-less odbc.ini file (adapted from previous example)

;
;  odbc.ini
;
[ODBC Data Sources]
 JDBC = Sybase JDBC Server

[JDBC]
Driver          = /usr/local/freetds/lib/libtdsodbc.so
Description     = Sybase JDBC Server
Trace           = No
Server          = JDBC
Database        = pubs2
Port            = 4444
TDS_Version     = 5.0

[Default]
Driver          = /usr/local/freetds/lib/libtdsodbc.so