FreeTDS User Guide: A Guide to Installing, Configuring and Running FreeTDS | ||
---|---|---|
Prev | Chapter 5. How to get what works with it working | Next |
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
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.aThe -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.
As of version 0.61, FreeTDS supports DSN-less connections and freetds.conf-less connections.
No connection information is specified in odbc.ini.
All connection information is specified in odbc.ini, without the need for freetds.conf.
Table 5-1. Connection attributes
Name | Default | Meaning | Possible Values | In odbc.ini |
---|---|---|---|---|
DSN | none | Use 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 entry | no |
Servername | none | This 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 section | yes |
Server | none | This specifies the hostname of a server. Used in freetds.conf-less configuration. | A server name or (ip) address | yes |
Port | Depends on the TDS version specified with configure | The tcp/ip port of SQL Server. | Any TCP port | yes |
UID | none | Can 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 username | no |
PWD | empty | Can 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). | Any | no |
TDS_Version | Depends on the TDS version specified with configure | TDS protocol version to use (ie 5.0, 7.0). | Any valid protocol version | yes |
APP | none | Application name. | Any | yes |
WSID | Computer name | Can be specified only for a DSN-less connection. Name of the local computer, sent to server. | Any | no |
LANGUAGE | us_english | Language used by server. | Any | yes |
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