Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Dear Perl Monks

I am running a Perl script on a Linux server and accessing a MsSQL database on another server. Most everything is fine except for one query. When I run a SELECT, parse through the returned data and then attempt a table update on the same table, the database locks. When I go to the database itself and try to look at the table, I get the "Waiting to execute query" message. When I kill the script back on the Linux server, everything immediately starts to work again with no issues.

The script and query throw no errors. There is no indication that something is wrong. Has anyone else seen anything like this? If you have, what was your solution?

I have a code snippet below that shows what I am trying to do. The problem happens when I try to run the second query.

~Ed

#!/usr/bin/perl -w use DBI; #### Make a database connection eval { $MY_CONNECTION = DBI->connect("$SERVER", "$UID", "$PWD", {PrintErr +or => 0}) or die "Cannot connect: $DBI::errstr\n"; }; if ($@) { print "ERROR: Database issue. The error was: $@"; exit(2); } #### Get the data my $GET_DB_DATA = $MY_CONNECTION->prepare("SELECT Field_1, Field_2, Fi +eld_3 " . "FROM " . $TableName . " " . + "WHERE Field_4 = 'foo' "); eval { $GET_DB_DATA->execute() or die "Database issue. $DBI::errstr\n"; }; if ($@) { print "ERROR: Cannot get table data. The error was: $@"; exit(2); } else { while ( my @RETURNED_DATA_ARRAY = $GET_DB_DATA->fetchrow ) { if ( $RETURNED_DATA_ARRAY[0] ne $RETURNED_DATA_ARRAY[1] ) { #### Update the table data my $UPDATE_TABLE = $MY_CONNECTION->prepare("UPDATE " . $Ta +bleName . " " . "SET Field_2 = +'" . $RETURNED_DATA_ARRAY[0] . "' " . "WHERE Field_3 += '" . $RETURNED_DATA_ARRAY[2] . "'"); eval { $UPDATE_TABLE->execute() or die "Database issue. $DBI: +:errstr\n"; }; if ($@) { print "ERROR: Cannot update table data. The error was +: $@"; exit(2); } } }

In reply to Perl Query Locks A MsSQL Database by EEddieEmm

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (9)
    As of 2014-10-21 04:50 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (96 votes), past polls