[freetds] issues connecting with perl DBD::ODBC

Kulik, Scott SKulik at severstalna.com
Tue Jun 23 11:03:10 EDT 2009

Anyone have any luck getting connected to a SQL server database with
DBD::ODBC in perl?  I'm hoping to try to get this issue fixed this week
but I'm out of ideas.

Scott K

-----Original Message-----
From: freetds-bounces at lists.ibiblio.org
[mailto:freetds-bounces at lists.ibiblio.org] On Behalf Of Kulik, Scott
Sent: Friday, June 19, 2009 5:20 PM
To: freetds at lists.ibiblio.org
Subject: [freetds] issues connecting with perl DBD::ODBC



  I am trying to connect to a SQL Server from perl.  I have successfully
configured ODBC and freetds under Redhat Linux ES4 and am able to
connect with tsql and isql.  For some reason though, the test perl
connection script is coming back with an error.


Here is my info:


[root at trafficdev1 root]# cat /etc/odbc.ini


Driver                  = FreeTDS

Description             = ODBC via FreeTDS

Servername              = SPT-SQL02

Database                = PTT


[root at trafficdev1 root]# cat /etc/odbcinst.ini

# Driver from freetds package


Description     = ODBC for SQL Server

Driver = /usr/local/lib/libtdsodbc.so

Setup = /usr/lib/libtdsS.so




        host = SPT-SQL02.DOMAIN.COM

        port = 1433

        tds version = 8.0

        client charset = UTF-8


Here is the sample perl script I am using from the freetds site:




use DBI;


my $dbh = DBI->connect('dbi:ODBC:PTT', 'user', 'pass', {PrintError =>


die "Unable for connect to server $DBI::errstr"

    unless $dbh;


my $rc;

my $sth;


$sth = $dbh->prepare("select \@\@servername");

if($sth->execute) {

    while(@dat = $sth->fetchrow) {

                print "@dat\n";




Here is the output from the script:

[root at trafficdev1 root]# ./test_odbc.pl

Unable for connect to server  at ./test_odbc.pl line 7.


I have been playing around with different perl scripts for a while now
but haven't had any success yet.  I would really appreciate if anyone
else has some ideas.  Thanks!


Scott K

FreeTDS mailing list
FreeTDS at lists.ibiblio.org

More information about the FreeTDS mailing list