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.
New configuration method (dnsless and freetds.conf'less)
Current CVS version support DSNless connection and freetds.conf'less connection. This mean that all connection informations can be stored in odbc.ini. To support this method some options has been added.
Table 5-1. odbc.ini entries
Name | Default | Meaning | Possible Values |
---|---|---|---|
Servername | none | This is old server specification. This refer to freetds.conf server name, not real server. If you want to use freetds.conf'less configuration use Server instead. | A valid freetds.conf server section |
Server | none | This specify the name of the real server. Used in freetds.conf'less configuration. | A server name or an address (ip) |
Port | depend from TDS version specified with configure | The tcp/ip port of SQL Server. | Any TCP port |
UID | none | This can be specified only in dsnless connection (for security reason do not store user/password on configuration file). To use domain authentication and specify domain use the format "domain\password". | Any valid user |
PWD | empty | This can be specified only in dsnless connection (for security reason do not store user/password on configuration file). Clear text password (use domain password for domain authentication). | Any |
TDS_Version | depend from TDS version specified with configure | TDS protocol version to use (ie 5.0, 7.0). | Any valid protocol version |
APP | none | Application name. | Any |
WSID | Computer name | Can be specified only in dsnless connection. Name of the computer sended to server. | Any |
LANGUAGE | us_english | Language used by server. | Any |
Example 5-3. Sample DSNless 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