#!perl use strict; use DBI; $|=1; my %INI; $INI{DSN} = 'Casinfo-SQL'; $INI{DBuser} = 'sa'; $INI{DBpass} = 'diamond'; my $dbh; # database filehandle my $stmt; my $userid = 1; print "before connect\n"; if ( $dbh = DBI->connect("DBI:ODBC:$INI{DSN}",$INI{DBuser},$INI{DBpass}) ) { $dbh->{AutoCommit} = 0; # enable transactions, if possible $dbh->{RaiseError} = 1; print "connected\n"; eval { my $stmt = "exec sp3PTSdrawing $userid"; print "before |$stmt|\n"; my $success = sDB_EXEC($stmt,$dbh); $dbh->commit; print "commited\n"; }; if ($@) { warn "Transaction aborted because $@"; eval { $dbh->rollback }; print "rolled back\n"; } $dbh->disconnect(); print "disconnecting\n"; } else { print "ERROR:Could not connect to database (ODBC DSN) |$INI{DSN}| $DBI::errstr \n"; } # end if ( $dbh = DBI->connect("DBI:ODBC:$INI{DSN}",$INI{DBuser},$INI{DBpass}) ) ########################################################################## sub sDB_EXEC { my $stmt = $_[0]; my $dbh = $_[1]; my $debugthreshhold = 2; my $rc; # record count of lines inserted if ( $rc = $dbh->do($stmt) ) { print "IN sDB_EXEC: $stmt RETURNS $rc\n"; } else { print "ERROR: could not |$stmt| error|$DBI::err|$DBI::errstr and |$!|\n"; } return $rc; } #### exec sp3PTSdrawing 1 #### before connect connected before |exec sp3PTSdrawing 1| IN sDB_EXEC: exec sp3drawing 1 RETURNS 1 commited disconnecting