DBD::Sybase 1.05_1 and Perl threads



Hi,

I am using Perl 5.8.5 on Linux RedHat Enterprise, DBD::Sybase 1.05_1,
OpenClient 12.5.1, connecting to Sybase IQ 12.6.

In my Perl script, I spawn several threads, each making a single
connection to a separate database.

>>From time to time, I experience the following error:

thread failed to start: install_driver(Sybase) failed: DBD::Sybase
initialize: ct_callback(clientmsg) failed at
/usr/lib/perl5/5.8.0/i386-linux-thread-multi/DynaLoader.pm line 249.
Compilation failed in require at (eval 14) line 3.

This will kill the current thread, and if I start another one, it will
be fine. Also, this tends to be on the first thread launched (about 80%
of the time). However, I am having trouble diagnosing the root cause of
this problem.

============== start snippet of code =================
use DBI;
use threads;

sub main
{
....
## Trigger a thread to execute SQL for each DB.
foreach $db_id (@db_ids)
{
$threads->{$db_id} =
threads->create(\&run_multiple_sql, $db_id, $sql);
} ## End of thread setup

## Now that we are done with the threads, make sure
## they're all done before moving on to next query
foreach $db_id (keys %{$threads})
{
## get results from the thread
eval{ $ok = $threads->{$db_id}->join() };

## Verify that return status was ok.
if ( ( $@ ) || ( !$ok ) )
{
## Log error and send email notification
&ln( "[error] Thread for $db_id when sql = '$sql': $@"
);
}
else
{
$processed_ds_counter++;
}
}
....
} ## end of main

##################################################################
## run_multiple_sql:
## Takes in a db_id and an sql query that has multiple
## statements (like a stored proc).
## All interactions are logged to the log file for this pid.
## Returns if there were no errors. Otherwise, dies. (this
## function should be executed as a thread so only that thread
## is affected).
##################################################################

sub run_multiple_sql
{
my ($db_id, $sql) = @_;
my ($dbh, $query, $results, $row) = ();

## 1. Open DB connection
$dbh =
DBI->connect("dbi:Sybase:server=".$::DB_GLOBAL_CONFIG{$db_id}{db_name}
.";timeout=".$::DB_TIMEOUT,
$::DB_GLOBAL_CONFIG{$db_id}{username},
$::DB_GLOBAL_CONFIG{$db_id}{password},
{PrintError => 1,RaiseError => 0, AutoCommit => 1 })
|| die("Cannot connect to datasource: $DBI::errstr");

$dbh->{syb_show_sql} = 1;
# $dbh->trace(3, "/tmp/dbi_trace.log");

## 2. Prepare and execute SQL
($query = $dbh->prepare($sql))
|| ($dbh->disconnect() && die("($db_id) Cannot prepare query:
$DBI::errstr\n$sql"));

($query->execute())
|| ($dbh->disconnect() && die("($db_id) Cannot execute query:
$DBI::errstr\n$sql"));

## 3. Get results
## syb_result_type indicates:
## 4040 CS_ROW_RESULT data incomplete, only 1 row
## 4043 CS_STATUS_RESULT successful exec of a storeddproc
## 4046 (no name) successful SQL select
## In other words, loop until we get the 4046 or 4043 code
while (! ($query->{syb_result_type} == 4046)
|| ($query->{syb_result_type} == 4043))
{
$results = $query->fetch();

## If error thrown by the database
if ($DBI::err)
{
$dbh->disconnect();
## Log, send email, and die
&lnd("($db_id) Cannot get results: $DBI::errstr\n$sql");
};

## If something was returned, let's see what it is
if ($results)
{
$row = join(" ", @{$results});
print ($query->{syb_result_type}, ": $row\n") if
($::DEBUG);
&log_to_file("($db_id) $row") if ($row);

## If line printed was an error: log, notify, die.
if ($row =~ /error/i) {
$dbh->disconnect();
&lnd("[error]: ($db_id) could not execute $sql.
$DBI::errstr\n\t$row");
}
## If line printed was a warning: log, notify.
if ($row =~ /(warning|\!\!\!)/i) {
&ln("[warning]: ($db_id) warning generated while
executing $sql.\n\t$row");
}
}
}
if ($DBI::err)
{
$dbh->disconnect();
die("($db_id) Cannot get results: $DBI::errstr\n$sql");
}

## 4. Finish query and disconnect from DB
$query->finish;
$dbh->disconnect();

## 5. Return results
return (1);

}

============== end snippet of code =================


Not sure if this is related. Not sure if this is a known problem in
DBD::Syabase. Not sure if it's been addressed in DBD::Sybase 1.06 or
1.07 (the Changes document has no reference to this).

Also, in the Sybase IQ log I don't see an attempt to connect (or any
activity at all) at the time the thread failed.

Please let me know what other information would be useful.

Thank you for your help,
-A Lattke

.



Relevant Pages

  • Re: Sybase DB - Ende nach der 2. Abfrage
    ... > Trotzdem schaffe ich nur grob 2 Abfragen auf die DB bevor einfach nix ... > mehr geht und die Verbindung nicht mehr klappt. ... > die Sybase auf einen MSSQL klappt wunderbar beliebig oft. ... dass Dein Data Provider ein Problem mit dem Connection ...
    (de.comp.datenbanken.misc)
  • Re: connection string causes blank page
    ... > I am developing a website in ASP that connects to a Sybase database. ... nor the connection. ... Further, the Sybase ... > I have also tried using a Data Source .ids file within the connection ...
    (microsoft.public.inetserver.asp.general)
  • connection string causes blank page
    ... I am developing a website in ASP that connects to a Sybase database. ... nor the connection. ... I have also tried using a Data Source .ids file within the connection string ...
    (microsoft.public.inetserver.asp.general)
  • Perl socket problem
    ... I'm attempting to use a perl script to interface with my Visual Basic 6 program using Winsock. ... print "Connection closed...\n";} ... You must get the line of data and scan it for a character that lets the perl script that the line is done. ... I haven't found any examples on the internet on how to do it, just that everyone says it can be done. ...
    (comp.lang.perl)
  • Re: script for sending email with experimental results
    ... I am running MATLAB code which typically takes a few hours, ... Is it necessary to write like a Perl script? ... man nail ... connection. ...
    (comp.soft-sys.matlab)