[freetds] issues connecting with perl DBD::ODBC

Kulik, Scott SKulik at severstalna.com
Fri Jun 19 17:19:31 EDT 2009


Hi,

 

  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

[PTT]

Driver                  = FreeTDS

Description             = ODBC via FreeTDS

Servername              = SPT-SQL02

Database                = PTT

 

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

# Driver from freetds package

[FreeTDS]

Description     = ODBC for SQL Server

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

Setup = /usr/lib/libtdsS.so

 

/usr/local/etc/freetds.conf

[SPT-SQL02]

        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:

 

#!/usr/bin/perl

 

use DBI;

 

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

 

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




More information about the FreeTDS mailing list