alex452 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am trying to set up one of my companys perl applications which uses a MS Sql Server 2005. The applications is known to work in our other environment but this times it seems to be a problem somewhere when application is trying to connect to the DB. I verified that Sql Server is responding on that ip and port by running a tsql command which comes whith freetds perl module. While trying to find a reason why its not working i also did a test below and the result i get is some kind of network fail. So what could be the problem? I tried to reinstall the DBI package but in vain. #!/usr/bin/perl use DBI; my $dbh = DBI->connect ("DBI:Sybase:server=xxx.xx.xx.xx:1433;database=JACKPOT", "sa","xxxxx" ) or die ("Cannot connect to database: $DBI::errstr");
  • Comment on Sql server + DBI package + freetds module = problem :)

Replies are listed 'Best First'.
Re: Sql server + DBI package + freetds module = problem :)
by imp (Priest) on Jan 25, 2007 at 14:16 UTC
    Could you provide the DBI error string? Saying "it failed" doesn't provide enough information to diagnose your problem.
      here is what i see from my test script above ----------------- DBI connect('server=212.247.84.54:1433;database=JACKPOT','sa',...) failed: OpenClient message: LAYER = (6) ORIGIN = (8) SEVERITY = (5) NUMBER = (3) Server 212.247.84.54:1433, database Message String: ct_connect(): directory service layer: internal directory control layer error: Requested server name not found. at alextest11.pl line 4 Cannot connect to database: OpenClient message: LAYER = (6) ORIGIN = (8) SEVERITY = (5) NUMBER = (3) Server 212.247.84.54:1433, database Message String: ct_connect(): directory service layer: internal directory control layer error: Requested server name not found. --------------

        Specifying an ip address and port number is not the normal way to connect to a Sybase (or MSSQL) database ... check out the "Connecting to Sybase" section of DBD::Sybase - especially the "interface file" section.

        -derby

        Update: Following my own advice, you can bypass the interface files by specifying host and port in the DSN:

        $dbh = DBI->connect( "dbi:Sybase:host=db1.domain.com;port=4100", $user, $passwd);

Re: Sql server + DBI package + freetds module = problem :)
by Melly (Chaplain) on Jan 25, 2007 at 12:03 UTC

    That connect string looks... odd. ("Sybase"?)

    My sql-server connect strings tend to look like:

    use DBI; my $data_source = "dbi:ODBC:driver={SQL Server};Server=$host;database= +$database;uid=$login;pwd=$password;"; my $dbcon = DBI->connect_cached($data_source,$login,$password,{PrintEr +ror=>0,RaiseError=>0,AutoCommit=>1});
    map{$a=1-$_/10;map{$d=$a;$e=$b=$_/20-2;map{($d,$e)=(2*$d*$e+$a,$e**2 -$d**2+$b);$c=$d**2+$e**2>4?$d=8:_}1..50;print$c}0..59;print$/}0..20
    Tom Melly, pm@tomandlu.co.uk

        Apart from the excellent resources mentioned above, the only really tricky part of all this was that I never did get DBD::Sybase to work for any version later than 0.91. You might be encountering a similar problem ... ?

      Melly:

      For your amusement:

      The "Sybase" token makes a bit more sense when you look at the history of MS SQL Server. MS acquired the code from Sybase (around version 4.2, if I recall correctly), and grew it from there. I originally learned databases on Sybase, and when I moved to MS SQL Server, I was quite surprised at how nearly *all* of my experience and favorite scripts worked without modification.

      --roboticus

Re: Sql server + DBI package + freetds module = problem :)
by Anonymous Monk on Jan 25, 2007 at 09:10 UTC
    So what could be the problem?
    some kind of network problem
      no even if the error message says "Cannot connect to database: OpenClient message: LAYER = (6) ORIGIN = (8) SEVERITY = (5) NUMBER = (3)" its hardly a network problem (tsql does work to connect to that database) rather a problem in something DBI package or that freetds module uses (http://www.freetds.org/) Any body who have a good grip of those 2 modules?