I had a couple of problems when running a Perl test script that attempted to connect to a SQL Server DB using the DBD::Sybase library. I found out fairly quickly that the error came from a missing entry in a config file for Freetds located at /usr/local/freetds/etc/freetds.conf. Once that was established, the solution was easy...
The script I was running looked like this:
-
#/usr/local/bin/perl -w
-
#
-
use strict;
-
use DBI;
-
-
my $dbh = DBI->connect("dbi:Sybase:myDB", 'user', 'password',{PrintError => 1});
-
The output when running gave me this:
$ perl -w conntest.pl
DBI connect('myDB','user',...) failed: OpenClient message:
LAYER = (0) ORIGIN = (0) SEVERITY = (78) NUMBER = (41)
Server hydra, database
Message String: Server is unavailable or does not exist.
at conntest.pl line 6
Unable for connect to server OpenClient message:
LAYER = (0) ORIGIN = (0) SEVERITY = (78) NUMBER = (41)
Server hydra, database
Message String: Server is unavailable or does not exist.
What was going on? A quick cat /usr/local/freetds/etc/freetds.conf | more and it was apparent that there was no entry for 'myDB'. I entered the following DB host information into the file to hopefully amend the situation...
[myDB] host = myDBHost port = 1433 tds version = 7.0
...and ran the test again, with an extra line appended to the test script:
-
#/usr/local/bin/perl -w
-
#
-
use strict;
-
use DBI;
-
-
my $dbh = DBI->connect("dbi:Sybase:myDB", 'user', 'password',{PrintError => 1});
-
-
-
$dbh->trace( 2 );
The $dbh->trace( 1 ) line gives you a trace of runtime information from DBI. Here I have used trace level 1 which shows only returned values and errors but there are a few more tracing levels available, each giving you more detailed information. See here for more about DBI::Trace.
$ perl -w conntest.pl DBI::db=HASH(0x1019c3ec) trace level set to 0x0/2 (DBI @ 0x0/0) in DBI 1.52-ithread (pid 432) -> DESTROY for DBD::Sybase::db (DBI::db=HASH(0x1019c3ec)~INNER) thr#10010200 < - DESTROY= undef
Joy! No errors!










Tech Messages | 2007-10-05 | Slaptijack says:
[...] chris ramsay» Blog Archive » Resolving Connection Problems With FreeTDS – This saved me from a humongous headache. [...]
October 6th, 2007 at 1:39 am