Here is my sample code which iam using to replicate the dead lock and using trycatch to handle the dead lock

Transaction A:sample

use strict; use DBI; use Execption::Class:TryCatch; ###opening connections try eval{ my $sql = "BEGIN TRAN \n"; my $sql1 = "Update dead_test set a = '11' where b= 1 \n"; my $sql2 = "WAITFOR DELAY '00:00:05'\n" my $sql3 = "Update dead_test1 set a = '22' where b= 2 \n"; my $sql4 = "COMMIT \n" ; $sql = $sql.$sql1.$sql2.$sql3.$sql4; $sql = $dbh->pepare($sql); $sql ->execute(); }; if catch(my $err){ print $err; eval { $dbh - >rollback }; }

Transaction B:sample

use strict; use DBI; use Execption::Class:TryCatch; ###opening connections try eval{ my $sql = "BEGIN TRAN \n"; my $sql1 = "Update dead_test1 set a = '11' where b= 2 \n"; my $sql2 = "WAITFOR DELAY '00:00:05'\n" my $sql3 = "Update dead_test set a = '22' where b= 1 \n"; my $sql4 = "COMMIT \n" ; $sql = $sql.$sql1.$sql2.$sql3.$sql4; $sql = $dbh->pepare($sql); $sql ->execute(); }; if catch(my $err){ print $err; eval { $dbh - >rollback }; }

Iam executing both the transaction from 2 unix sessions parallel. As of now it doesn;t return or print any error. The question is how to capture the error from that is return from database and rollback if it is a deadlock error (erronumber 1205).


In reply to Re^4: Dead Lock replication in Sql server by sunil19
in thread Dead Lock replication in Sql server by sunil19

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.