Dear Monks,

I'm trying to call a stored procedure in an Oracle database multiple times and have them run in parallel using Parallel::ForkManager. To do so, I've created multiple database and statement handles that will be called one at a time within the parallel loop based on the loop counter value. However, I continue to receive multiple instances of the following error each time I run the program:

DBD::Oracle::db do failed: handle 2 is owned by thread 158fe8 not current thread 3c30cb8 (handles can't be shared between threads and your driver may need a CLONE method added) at test6.pl line ...

The code is below. What am I doing wrong?

Thank you for your help!

#!/usr/bin/perl use Parallel::ForkManager; use DBI; use strict; my $dbh=DBI->connect("dbi:Oracle:dbname","username","password",{RaiseE +rror => 1 , PrintError => 0}); my $dbh1=DBI->connect("dbi:Oracle:dbname","username","password",{Raise +Error => 1 , PrintError => 0}); my $dbh2=DBI->connect("dbi:Oracle:dbname","username","password",{Raise +Error => 1 , PrintError => 0}); my $dbh3=DBI->connect("dbi:Oracle:dbname","username","password",{Raise +Error => 1 , PrintError => 0}); my ($sth1, $sth2, $sth3); # statement handles my ($sqlstmt1, $sqlstmt2, $sqlstmt3); # statements to be execut +ed my @num_array = ("1", "2", "3"); my $mid = $#num_array; my $t = localtime(); my $pm = new Parallel::ForkManager($mid + 1); for (my $mid_cnt = 0; $mid_cnt <= $mid; $mid_cnt++) { $pm->start and sleep 30 and next; ## Beginning of parallel +process. print $x "For Number $num_array[$mid_cnt]:\n"; if ($num_array[$mid_cnt] == 0) { $t = localtime(); print "Calling procedure for Number $num_array[$mid_cnt] at $t +\n"; $sqlstmt1 = "BEGIN TEST_PROC($num_array[$mid_cnt]); end;"; $sth1 = $dbh1->do($sqlstmt1) or die $dbh1->errstr; $t = localtime(); print "Done with procedure for Number $num_array[$mid_cnt] at +$t\n\n"; } elsif ($num_array[$mid_cnt] == 1) { $t = localtime(); print "Calling procedure for Number $num_array[$mid_cnt] at $t +\n"; $sqlstmt2 = "BEGIN TEST_PROC($num_array[$mid_cnt]); end;"; $sth2 = $dbh2->do($sqlstmt2) or die $dbh2->errstr; $t = localtime(); print "Done with procedure for Number $num_array[$mid_cnt] at +$t\n\n"; } else { $t = localtime(); print "Calling procedure for Number $num_array[$mid_cnt] at $t +\n"; $sqlstmt3 = "BEGIN TEST_PROC($num_array[$mid_cnt]); end;"; $sth3 = $dbh3->do($sqlstmt3) or die $dbh3->errstr; $t = localtime(); print "Done with procedure for Number $num_array[$mid_cnt] at +$t\n\n"; } $pm->finish; ## End of parallel process. } $pm->wait_all_children; $dbh1 -> disconnect; $dbh2 -> disconnect; $dbh3 -> disconnect;

In reply to Error Using Multiple Database Handles (DBD::Oracle::db do failed: handle 2 is owned by thread...) by alex.TT2

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.