FreeTDS User Guide: A Guide to Installing, Configuring, and Running FreeTDS
Prev | Chapter 4. Preparing ODBC | Next

# Troubleshooting ODBC connections

Supposing everything compiles and installs without trouble, how do you know if your ODBC setup works? Or, if you know it doesn't, what then?

First, try to connect with tsql. If you're intending to use `freetds.conf`, exercise it with tsql -S `servername`. If not, use TDSVER=7.0 tsql -H `hostname` -p `port`

If tsql works and isql doesn't, you've isolated the problem to the ODBC setup. FreeTDS might have some interoperability problems, but mere connection to the database isn't one of them! If tsql doesn't work, turn on logging with `TDSDUMP`. The log will tell you what TCP/IP name (and address) FreeTDS is attempting to connect to, and what version of the TDS protocol it's using.

## With iODBC

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 [1], then compile and link the program directly:

Example 4-7. Compile `odbctest` without a driver manager.

    $ 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.

## With unixODBC

Try isql -v `dsn` `username` `password`, and have a look at the log. See if the right address and TDS version are being used. Adjust to taste.

### Notes

[1] | When compiling directly to FreeTDS you still need the Driver Manager's header files.

Prev | Home | Next
ODBC-combined configuration | Up | Advanced Configurations