Code: FreeTDS Notes

Mac OS X, Perl, and Microsoft SQL Server

These are my notes on installing and configuring FreeTDS on Mac OS X to work with Perl and Microsoft SQL Server 2000

It's here for my own purposes, and you find it useful, well, then we both win.

(Note that some lines are long and may wrap, if you are using the command line, make sure they don't wrap...)

Our goal was to use Perl running on Mac OS X to connect to a Microsoft SQL Server running on Windows...

Version details:

Installing FreeTDS on Mac OS X

After you untar the thing, run configure with the following options:

./configure --disable-odbc --disable-libiconv

You then need to edit the libtool file. Somewhere around line 205 you should see:

archive_cmds="\$CC \$(if test .\$module = .yes; then echo -bundle; else echo -dynamiclib; fi) \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$linkopts -install_name \$rpath/\$soname \$verstring"

Remove this bit from the line: \$deplibs

Then do the regular stuff:

make clean
sudo make install

I'm not sure if you need the 'make clean' but I know I did because this took a few attempts... I'd do it anyway, as I don't think it will do any harm.

Configuring FreeTDS

Once that is all done, you need to configure the file at /usr/local/etc/freetds.conf

I just edited the entry after: "A typical Microsoft SQL Server 2000 configuration"

    host =
    port = 1433
    tds version = 8.0

I set the servername to "SQLServer2000" and it's found at "" (I didn't change the port or tds version.)

Using DBD::Sybase

If using bash (which is the default with Panther I believe) you might need to set the SYBASE environment variable:

set SYBASE=/usr/local
export SYBASE

should do it...

The DBD::Sybase install was pretty standard. (I did it outside of cpan, though this may be due to my multiple attempts at installing FreeTDS.)

Then in a perl script I've got:


use DBI;
use DBD::Sybase;

    $ENV{SYBASE} = "/usr/local";

$db = DBI->connect(


After that it should be the normal DBI stuff...

The bit with server=SQLServer2000 specifies the server, matching what we have in the freetds.conf file. We specified the database with the database=MyTestDatabase bit, then just add in the username and password, and shebang, it should work...



Ah, I was having problems with charsets and grabbing data from a Microsoft SQL Server, so added one more line to the server's config:

    host =
    port = 1433
    tds version = 8.0
    client charset = UTF-8

Which seems like it'll do the right thing now, which is convert WINDOWS-1252 to UTF-8