0

I'm trying to connect to a MS-SQL Database using perl and freetds. I have tested the installation of freetds using the unix commandline

`/usr/local/exec/bin/tsql -S myDB -I freetds.conf -U userName -P passw0rd -D DataBase1 -o q < query.sql` 

where query.sql contains my sql query. It runs perfectly well. But when I try the same with perl it gives me the following error -

`Your sybase home directory is /opt/sybase. Check the environment variable SYBASE if it is not the one you want! Cannot access file /opt/sybase/config/objectid.dat` 

but running

$ set | grep SYBASE yields SYBASE=/usr/fsf/freetds

Below is my perl code:

#!/usr/bin/perl5/core/5.8.8/exec/bin/perl

use lib qw(/usr/perl5/core/5.8.8/exec/lib);
use lib qw(/usr/perl5/DBI/1.607/exec/5.8/lib/perl5);
use lib qw(/usr/perl5/DBD-Sybase/1.09/exec/5.8/lib/perl5);

use DBI;
use DBD::Sybase;

my $user   = "userName";
my $passwd = "passw0rd";
my $server = "myDB";

`export SYBASE=/usr/fsf/freetds`;
`export LD_LIBRARY_PATH=/usr/fsf/freetds/0.82/exec/lib`;
`export FREETDSCONF=./freetds.conf`;

my $dbh = DBI->connect("DBD:Sybase:server=$server", $user, $passwd, {PrintError => 0});

unless ($dbh) {
    die "ERROR: Failed to connect to server ($server).\nERROR MESSAGE: $DBI::errstr";
} 
else {
    print "\n";
    print "Successful Connection.";
}

Any help much appreciated!

MattO
  • 13
  • 8
  • which version of perl "perl -v" ? – keety Oct 22 '14 at 14:32
  • 1
    The path to your drivers says 5.10. You might have downloaded the drivers for the wrong version of perl. Either update to 5.10.1 or get the drivers for 5.8.8. – AKHolland Oct 22 '14 at 14:37
  • thanks @AKHolland . I've corrected that. And that problem's gone but now it says `Your sybase home directory is /opt/sybase. Check the environment variable SYBASE if it is not the one you want! Cannot access file /opt/sybase/config/objectid.dat` but running `$ set | grep SYBASE` yields `SYBASE=/efs/dist/fsf/freetds` Am i missing something? – MattO Oct 23 '14 at 09:41
  • I'm not sure about that... I'm going to post my previous comment as an answer, though, for anyone else who runs into this. – AKHolland Oct 23 '14 at 11:30

2 Answers2

1

The path to your drivers says 5.10. You might have downloaded the drivers for the wrong version of perl. Either update to 5.10.1 or get the drivers for 5.8.8.

AKHolland
  • 4,435
  • 23
  • 35
1

I have figured it out. Well, you need to first set the SYBASE environment variable before you install DBD-Sybase. And that's the reason behind Your sybase home directory is /opt/sybase when it is supposed to point to the freetds installation location. Ref: http://www.idevelopment.info/data/SQLServer/DBA_tips/Programming/PROG_4.shtml#Install%20DBD-Sybase

MattO
  • 13
  • 8