2

I have a perl script which connects to a Sybase db server (alias for server - MYDATABASESERVER). My code is:

exec perl -w -x
#!perl

use Sybase::DBlib;
use Mail::Sendmail;
use Env qw(DSQUERY DBNAME DBUSER DBPASSWD);

$dbh = &execRemoteSQL($sql_text);

sub execRemoteSQL
{
my ($sqlText) = @_;
my ( $ret, $retS );
local ($dbh) = undef;


$dbh = new Sybase::DBlib $DBUSER, $DBPASSWD, $DSQUERY;
if ( !(defined $dbh) )
{
    print STDERR "execRemoteSQL(): Failed To Create DB Handle for :\n";
            print STDERR " SERVER    = $DSQUERY\n";
            print STDERR " DATABSE   = $DBNAME\n";
    exit(-1);
}
.
.
.

When i provide the server name as MYDATABASESERVER (value of DSQUERY), I get the error in the If statement, but it connects properly to the server with name as MYDB.

Wanted to know if there is any constraint on the server name length or is it due to something else.

Here is the error messsage i am getting:

DB-Library error:
        Unknown host machine name.
execRemoteSQL(): Failed To Create DB Handle for :
 SERVER    = MYDATABASESERVER
 DATABSE   = my_db

The server alias is defined properly because i am able to connect to the db using isql.

May
  • 21
  • 3
  • 3
    What is the actual error message? – Bryan Dec 20 '11 at 13:20
  • [Why use strict and warnings?](http://stackoverflow.com/questions/8023959/why-use-strict-and-warnings). – TLP Dec 20 '11 at 15:24
  • I can't help but notice that Sybase::DBlib has debugging built in: http://search.cpan.org/~mewp/sybperl-2.19/DBlib/DBlib.pm#Utility_routines Any reason you are not using it? – TLP Dec 20 '11 at 16:02

2 Answers2

1

I don't think the length of the server name is too long here.

What is your exact error message?

Maybe the MYDATABASESERVER server-alias name is not defined properly in the Sybase-specific "interfaces" config file. It resides in dir $SYBASE/$SYBASE_OCS. What does it say about MYDATABASESERVER (should be 2 lines)?

In any case: Don't use DBLib, it is really old and deprecated. I think the maintainer of the Sybperl/DBLib and DBD::Sybase modules, only still supports the Sybase::DBLib code to make life easier for client programmers who have to deal with old programs, and to keep legacy applications compatible with new releases of Sybase ASE.

You should use DBI and DBD::Sybase instead. 99% of all perl/sybase code on the internet uses DBI.

knb
  • 9,138
  • 4
  • 58
  • 85
  • Have changed the code to use DBD::Sybase and it is working fine now. @knb: Thanks a lot. – May Dec 21 '11 at 08:29
0

Can you try the following syntax instead? :

$dbh = Sybase::DBlib->new( $DBUSER, $DBPASSWD, $DSQUERY );
Zaid
  • 36,680
  • 16
  • 86
  • 155