holandes777 has asked for the wisdom of the Perl Monks concerning the following question:
When#!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},$IN +I{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; }
is executed from the Query Analyzer the procedure takes between 30 seconds and 2 minutes. It completes with lots of records being written to a table.exec sp3PTSdrawing 1
However, the resulting set of records is incomplete. It is as if the execution timed out but was still deemed OK. The partial record set is committed to the database.before connect connected before |exec sp3PTSdrawing 1| IN sDB_EXEC: exec sp3drawing 1 RETURNS 1 commited disconnecting
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI - ODBC- do - MSSQL stored procedure - does not complete but returns "ok"
by Devanchya (Beadle) on Dec 15, 2006 at 16:28 UTC |