Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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.


#!/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

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, 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
  • 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (5)
    As of 2018-06-23 03:29 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (125 votes). Check out past polls.