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: "Todd E dot Scheresky" <tscheresky at micron dot com>
Subject: Dead connections
Date: Dec 11 1997 8:02PM

Greetings,

This question IS NOT for the faint of heart.  First some background.  I
am running Perl 5.004_04, Sybperl 2.07, on AIX 4.1.3.  The Perl script,
extremely bastardized, follows at the end of this email.

I run the script in two ways.  First, from the command line and second,
I call the subroutine "resolveIP" repeatedly from a C program.  From the
command line the script runs fine.  From the C program the script runs
fine on the first call to "resolveIP".  However, if I call "resolveIP" a
second time, and repeatedly thereafter, on the first host "getIP" dies
because ct_execute returns a CS_FAIL.  It's as if the database
connection to Sybase is no longer valid.  This is confusing to me.  The
database connection should have been cleaned up and dropped after
exiting the subroutine "resolvedIP", and every time I call "resolveIP" I
should get a new connection, but this is not happening as far as I can
tell.  I thought that maybe the connection was being cached and
subsequently timing out so I tried calling ct_config to set the timeout
to longer than 60 seconds and ct_config failed with the following error.

I used "ct_config(CS_SET, CS_LOGIN_TIMEOUT, 900);" I got back:

Open Client Message: (In msg_cb)
Message number: LAYER = (1) ORIGIN = (1) SEVERITY = (1) NUMBER = (9)
Message String: ct_config(SET,LOGIN_TIMEOUT): user api layer: external
error: The buflen parameter must be set to CS_UNUSED.

So what the heck is happening here?  Why can I only run "resolvedIP"
successfully once?

Any help would be greatly appreciated!

Todd E. Scheresky
Systems Programming
Micron Technology, Inc.

-----------------------------

#!/usr/local/perl5004/bin/perl

use FileHandle;
use Sybase::CTlib;

&resolveIP();

sub resolveIP
{
  ## Login information.
  my $uid = 'SQLLOGINID';
  my $pwd = 'SQLPASSWRD';
  my $srv = 'SQLSERVER1';

  my ( $dbh,$ip,$host,@file );

  ## Open the Sybase connection.
  if ( ($dbh = new Sybase::CTlib $uid, $pwd, $srv) == 0 )
  {
    die "Error: Login to Sybase failed!\n";
  }

  

  foreach $host (@file)
  {
    $ip = getip($host,\$dbh);

    
  }
}

sub getip
{
  ##
  ## The host name of the server is a passed parameter.
  ##
  my ( $hostname,$dbh ) = @_;

  ##
  ## Local variables.
  ##
  my ( $ipaddr,$sqlc,$rowval );

  $sqlc = "sel_TCPIP_address_by_alias \"$hostname\"";

  $$dbh->ct_execute($sqlc);

  while ( ($rc = $$dbh->ct_results($restype)) == CS_SUCCEED )
  {
    next if ( $restype == CS_CMD_DONE ||
              $restype == CS_CMD_FAIL ||
              $restype == CS_CMD_SUCCEED );
    while( @dat = $$dbh->ct_fetch )
    {
      if ( $restype == CS_ROW_RESULT )
      {
        if ( length($dat[0]) > 0 )
        {
          $ipaddr = $dat[0];
        }
      }
      if ( $restype == CS_STATUS_RESULT )
      {
        $resval = $dat[0];
      }
    }
  }
  if ( $rc != CS_FAIL )
  {
    if ( $resval != 0 )
    {
      $ipaddr = "";
    }
  }
  else
  {
    die "execute: sel_TCPIP_address_by_alias returned CS_FAIL";
  }
  return($ipaddr);
}