This is the situation in which I've found the finish() method to be required using DBD::ODBC. It appears that every second execute statement is dying. I am using: WinXP Perl 5.8.0 (ActiveState) DBI 1.30 (from ActiveState) DBD::ODBC 0.43 (from ActiveState)
Paul ### CODE ########## use strict; use DBI; my $dbh = DBI->connect("dbi:ODBC:test_data"); my $sql1 = "select daughter from daughters"; my $sql2 = "select count(*) from spot_assignment where daughter = ?"; my $sth1 = $dbh->prepare($sql1); my $sth2 = $dbh->prepare($sql2); $sth1->execute(); while (my $daughter = $sth1->fetchrow_array()) { $sth2->execute($daughter); my $count = $sth2->fetchrow_array(); if ($count) { print "$daughter\t$count\n"; } # $sth2->finish() # if this is uncommented runs smoothly } ### Output ######## H3006D11 1 DBD::ODBC::st execute failed: [Microsoft][ODBC Driver Manager] Invalid cursor state (SQL-24000)(DBD: st_execute/SQLExecute err=-1) at test.pl line 15. H3006E01 7 DBD::ODBC::st execute failed: [Microsoft][ODBC Driver Manager] Invalid cursor state (SQL-24000)(DBD: st_execute/SQLExecute err=-1) at test.pl line 15.