Below is a cut down (ie error checking removed etc) version of a script I'm working on. The idea is that I call stored procedures but use my own error handler to control execution
$dbh->{syb_err_handler} = \&err_handler;
There is no problem when the called procedure works OK but on error when I try to disconnect via the terminate function I get...
syb_db_disconnect(): ct_con_drop() failed
I've tried to clean up (calling finish on the statement handler) but can't get rid of the warning. Does any one have any other ideas?
#!/usr/local/bin/perl -w use strict; use DBI; use DBD::Sybase; my $dbh; my $sth; $dbh = DBI->connect( "DBI:Sybase:server=$ENV{'MY_SERVER'};database=$ENV{'MY_DB'}", $ENV{'MY_USER'}","$ENV{'MY_PASS'}", {AutoCommit => 1, PrintError => 0, RaiseError => 1}); # sql errors handler $dbh->{syb_err_handler} = \&err_handler; my $procedure_name = 'testproc'; $sth = $dbh->prepare("exec $procedure_name"); # Run the database procedure $sth->execute(); do { while (my $data = $sth->fetch()) { if ($sth->{syb_result_type} == CS_ROW_RESULT) { print @$data,"\n"; } } } while ($sth->{syb_more_results}); $dbh->disconnect; # Script ends sub err_handler { my($err, $sev, $state, $line, $server, $proc, $msg) = @_; if ($err == 0) { # This is ok print output print "$msg\n"; return 0; # This is not an error } else { # Problem encountered. my $errmsg = "Fatal error detected in procedure. $procedure_na +me\n"; $errmsg .= "Error number = $err\n"; $errmsg .= "Severity = $sev\n"; $errmsg .= "State = $state\n"; $errmsg .= "Line = $line\n"; $errmsg .= "Server = $server\n"; $errmsg .= "Procedure = $proc\n"; $errmsg .= "Message = $msg\n"; $sth->finish() if $sth; terminate($errmsg); } } sub terminate { my $errmsg = shift; print "$errmsg\n"; $sth->finish() if $sth; $dbh->disconnect if $dbh; exit 1; }

In reply to DBI disconnection problems by Jonathan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.