I am using the following function to retrieve the last date from an MSSQL table:
sub getlast{ my $panel = shift; my @lastsale; my $dbh; my $sth; $dbh = DBI->connect( "dbi:Sybase:server=$ini{SQL01DB}{server}; database=$ini{SQL01DB}{database}", $ini{SQL01DB}{usern +ame}, $ini{SQL01DB}{password} ); $sth = $dbh->prepare( "select convert(varchar,max(dtmTimeEnter +),120), convert(varchar,max(dtmDateTime),120) from $table where intSiteID=$site and intPanelID=$panel and intAdditiveCode>0" ); $sth->execute(); @lastsale = $sth->fetchrow; $sth->finish; $dbh->disconnect; if ( $lastsale[0] || $lastsale[1] ){ return ( @lastsale ); } else{ return; } }
This code generally works perfectly for my purposes. But, when the MSSQL server is under heavy load it seems to be incorrectly returning nothing for both elements in the lastsale array in some random instances. At first, I thought perhaps the server was refusing the connection (due to too many), but I don't believe this to be the case. If the connection is refused, then the prepare should cause an error that exits the script (right?). There are some instances that there will legitimately be nothing returned, and I need these. If anyone has a similar experience, or any ideas to help me troubleshoot this I would greatly appreciate it!

In reply to MSSQL and Perl - heavy load by taomanjay

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.