If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > CLI0129E No more handles.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-08-06, 12:21
ljrong ljrong is offline
Registered User
 
Join Date: Jan 2002
Location: USA
Posts: 53
CLI0129E No more handles.

DBD:B2::db prepare failed: [IBM][CLI Driver] CLI0129E No more handles. SQLSTATE=HY014 at ./comm_mim.pl line 35, <FD> line 5807.
Can't prepare statement: [IBM][CLI Driver] CLI0129E No more handles. SQLSTATE=HY014 at ./comm_mim.pl line 35, <FD> line 5807.

Thanks.
-Jianrong

My program is:

#!/usr/bin/perl -w
use DBI;
use DBD:B2::Constants;
use DBD:B2;
my $database='dbiB2:gene';

my $dbh = DBI->connect($database)
or die "Can't connect to $database: $DBI::errstr";

$first = shift(@ARGV) ;
$second= shift(@ARGV) ;
$column= shift(@ARGV) ;

open(FD,"<$first") || die "Couldn't open sourcefile\n";
open(FD1,">$second") || die "Couldn't open output file\n";
while($line= <FD>)
{
chop($line);
@a = split(/\|/,$line);
my $st = "SELECT NAME FROM U.SCT_CON_072005 WHERE SCTID=$a[$column] WITH UR";
my $sth = $dbh->prepare($st) or die "Can't prepare statement: $DBI::errstr";
my $rc = $sth->execute() or die "Can't execute statement: $DBI::errstr";
if (($name) = $sth->fetchrow())
{
print FD1 "$line|$name\n";
} else
{
print "ERROR SCT ID=$a[$column]\n"
}

$rc = $sth->finish;
$st ="";


}
$dbh->disconnect();
close(FD);
close(FD1);
Reply With Quote
  #2 (permalink)  
Old 12-08-06, 13:29
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
May be you should prepare the statement outside the loop, instead of creating 5000+ statement handles.
Reply With Quote
  #3 (permalink)  
Old 12-08-06, 13:50
ljrong ljrong is offline
Registered User
 
Join Date: Jan 2002
Location: USA
Posts: 53
I can't prepare the statement outside the loop, because it was changed within loop.

Thanks.
Reply With Quote
  #4 (permalink)  
Old 12-08-06, 14:39
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
May be you should read DBI documentation then...
Code:
my $st = "SELECT NAME FROM U.SCT_CON_072005 WHERE SCTID=? WITH UR";
my $sth = $dbh->prepare($st) or die "Can't prepare statement: $DBI::errstr";

while($line= <FD>)
{
  chop($line);
  @a = split(/\|/,$line);
  sth->bind_param(1,$a[$column]);
  my $rc = $sth->execute() or die "Can't execute statement: $DBI::errstr";
  ...
}

$rc = $sth->finish;
$st ="";
Reply With Quote
  #5 (permalink)  
Old 12-08-06, 15:27
ljrong ljrong is offline
Registered User
 
Join Date: Jan 2002
Location: USA
Posts: 53
Thank you n_i, it works great.
BTW, if the WHERE condition is variable, what can I do.
Anyway, thanks you so much.

-Jianrong
Reply With Quote
  #6 (permalink)  
Old 12-08-06, 18:12
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Well, if the query (its WHERE clause) changes you can't use this approach, obviously. If the number of query variants is small you can still prepare all of them ahead of time and execute the one you need in the loop, depending on some condition.

Otherwise you will need to make sure that the statement handle is destroyed at the end of each cycle.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On