The following code executes a lengthy (time consuming) stored procedure.
#!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; }
When
exec sp3PTSdrawing 1
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.
 
When the perl program is executed from the command prompt it takes about 8 seconds. The output of the program is as follows:
before connect connected before |exec sp3PTSdrawing 1| IN sDB_EXEC: exec sp3drawing 1 RETURNS 1 commited disconnecting
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.
 
In reading through the DBI there is code to allow the user to abort a transaction, but I don't see code to set maximum timeout limits. I thought it might be an ODBC timeout, but I see no timeouts in the ODBC setup, plus I have long running queries in perl scripts on this server (longer than 30 seconds).
 
Advice would be greatly appreciated.

In reply to DBI - ODBC- do - MSSQL stored procedure - does not complete but returns "ok" by holandes777

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.