PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: STattitali at Paragon-Mcs dot com (Sandesh Tattitali)
Subject: Multiple connections
Date: Dec 4 1997 7:13PM

Hi all,
	Let me first explain what I am doing before going on to the problem.
We have multiple Sybase installations on our Solaris box,one installation for each Sybase server that runs on the box. What I want to do is write a script that will access each server and retrieve some information. The key information for each Sybase server is is a CONFIG file with the format
# Server Name		Sa Password		$SYBASE		Runfile name
I read this file and retrieve the entries. For each Sybase server I want to 
1. Open a connection (using the CTlib module).
2. Retrieve the info
3. Close the connection.
My questions are.
1. How do I explicitly close a connection in the CTlib module ? The documents that I looked at said that the connection was automatically closed when the handle went out of scope (which I assume to be the end of the program since all the programs that I saw made use of just one connection).I am processing the information in a WHILE loop so if I try to use the same variable for a new connection (to a different SQL server) without closing the old connection,won't I have problems ? ( I am having problems though I am not too sure whether it is because of this reason).Does the handle go out of scope in the next loop of the WHILE statement ???
2. How do I set the SYBASE environment to change for each SQL Server ? I tried to use $ENV{SYBASE} = $SybaseDir but I keep getting errors.Also when I say use Sybase::CTlib , I need to have $SYBASE set. However I can only get $SYBASE from the file that I am reading. And the way I see it (I am fairly new to Perl) the 'use' statement is evaluated first so even if I have the 'use' statement after reading the CONFIG file,it still gives me problems.


Here is the code and the error

########################  CODE #########################

#!/usr/local/bin/perl

use Sybase::CTlib;

ct_callback(CS_CLIENTMSG_CB,\&msg_cb);
ct_callback(CS_SERVERMSG_CB, "srv_cb");

open(SYBASE_SERVERS,"SYBASE_SERVERS.cfg");
while ( $sybase_output =  )
{
  if ( $sybase_output =~ /^#/ )
  {
    next;
  }

  ($server,$password,$home_dir,$runfile) = split(' ',$sybase_output);
  print "$server,$password,$home_dir,$runfile \n";

  $run_file_path = "$home_dir/install/$runfile";
  $dataserver = 0;
  open (RUNFILE,$run_file_path);
  while ( $runfile_output = )
  {if ( $runfile_output =~ /dataserver/ )
    {
      $dataserver = 1;
    }
    if ($dataserver == 1)
    {
      if ( $runfile_output =~ /.*(c[0-9]t[0-7]d[0-9]s[0-7]).*/ )
      {
        $master_device = $1;
        print "@@@@ MASTER DEVICE for $server is $master_device \n";
      }
    }
  }
  close(RUNFILE);

 
  $ENV{SYBASE} = $home_dir;

  print "$ENV{SYBASE} ##### \n";

  print "$password $server \n";

  $db_conn = Sybase::CTlib->ct_connect('sa',$password,$server);$db_conn->ct_execute("select name,phyname from master..sysdevices");

  while (($db_conn->ct_results($restype)) == CS_SUCCEED)
  {
    next unless $db_conn->ct_fetchable($restype);

    while (($name,$slice) = $db_conn->ct_fetch())
    {
      print "ON SERVER $server we have DEVICE = $name PHY = $slice \n";
    }
  }
}
close(SYBASE_SERVERS);


I have tried moving the 'use' statement and the $ENV{SYBASE} = $home_dir statements all to no avail.

#################### ERROR #####################

 Open Client Message : (In msg_cb)
Message number: Layer = (7) ORIGIN = (2)SEVERITY = (6) NUMBER = (6)
Message String : ct_con_alloc(): unable to get layer message string: unable to get origin message string: error string not available
ct_con_alloc failed at sybase.pl line 46.
Can't call method "ct_execute" without a package or object reference at sybase.pl line 48.


Hope that I am not overlooking the obvious !!!!!!!

TIA
Sandesh