No Gravatar

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:

PERL:
  1. #/usr/local/bin/perl -w
  2. #
  3. use strict;
  4. use DBI;
  5.  
  6. my $dbh = DBI->connect("dbi:Sybase:myDB", 'user', 'password',{PrintError => 1});
  7.  
  8. die "Unable for connect to server $DBI::errstr" unless $dbh;

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:

PERL:
  1. #/usr/local/bin/perl -w
  2. #
  3. use strict;
  4. use DBI;
  5.  
  6. my $dbh = DBI->connect("dbi:Sybase:myDB", 'user', 'password',{PrintError => 1});
  7.  
  8. die "Unable for connect to server $DBI::errstr" unless $dbh;
  9.  
  10. $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!

  • Share/Save/Bookmark

One Comment on “Resolving Connection Problems With FreeTDS”

You can track this conversation through its atom feed.

  1. Tech Messages | 2007-10-05 | Slaptijack says:

    [...] chris ramsay» Blog Archive » Resolving Connection Problems With FreeTDS – This saved me from a humongous headache. [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>