Michael Peppler
Sybase Consulting
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
Sybase on Linux FAQ
Sybperl FAQ
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at MBAY dot NET>
Subject: How to find out when you're killed because of a deadlock?
Date: Apr 9 1998 2:18PM

Marc Merlin writes:
 > Hi,
 > I searched the archive and didn't find anything, so here's the question:
 > I have a script that does:
 >     #print "Running query \"$query\"\n";
 >     $self->dbcmd($query);
 >     ($self->dbsqlexec == &SUCCEED) or die "Died on query \"$query\": $!";
 >     $self->dbresults; 
 > It's been running beautifully for several weeks, but today the cron job
 > returned the following:
 > Msg 1205, Level 13, State 1
 > Line 2
 >         Your server command (process id #151) was deadlocked with another
 > process and has been chosen as deadlock victim.  Re-run your command.
 > DB-Library error:
 >         General SQL Server error: Check messages from the SQL Server. 
 > The funny thing is that when I get those kinds of errors (not deadlocks, but
 > typically  an incorrect  query), dbsqlexec  doesn't return  SUCCEED, and  my
 > script dies, showing the query that triggered the problem.

Whether dbsqlexec() returns FAIL for a problem or not depends on the
query. If there is only one result set, dbsqlexec() will *normally*
return FAIL, but you should always check the return code from
dbresults() too (which will return FAIL if the query failed for any
reason and dbsqlexec() returned SUCCEED).

BTW you can add deadlock detection by special coding a message handler 
to detect error 1205 and re-running the query when it's triggered.

Michael Peppler         -||-  Data Migrations Inc.    -||-
Int. Sybase User Group  -||-