in reply to Re^3: Dead Lock replication in Sql server
in thread Dead Lock replication in Sql server
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).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Dead Lock replication in Sql server
by Eily (Monsignor) on Jun 30, 2017 at 12:29 UTC | |
by sunil19 (Initiate) on Jul 03, 2017 at 05:56 UTC | |
by poj (Abbot) on Jul 03, 2017 at 07:50 UTC | |
|
Re^5: Dead Lock replication in Sql server
by AnomalousMonk (Archbishop) on Jun 30, 2017 at 15:47 UTC |