DBD::ODBC::st execute failed: [iODBC][Driver Manager]Invalid cursor state (SQL-24000)(DBD: st_execute/SQLExecute err=-1) at ./addstuname.pl line 21, chunk 2014. [iODBC][Driver Manager]Invalid cursor state (SQL-24000)(DBD: st_execute/SQLExecute err=-1) at ./addstuname.pl line 21, chunk 2014. #### #!/usr/bin/perl #use strict; use DBI; my $dbh = DBI->connect('dbi:ODBC:MY_DB') or die (DBI->errstr()); open INPUT, '/tmp/records.asc'; my $query = qq(select b from c where a = ?); # # Preparing here causes an error! # #my $sth = $dbh->prepare($query) # or die ($dbh->errstr()); while (my $rec = ) { chomp($rec); my @items = split(',', $rec); my $a = $items[6]; $a =~ s/#//; if ($items[7] eq '') { # If I prepare each time it works! # my $sth = $dbh->prepare($query) or die ($dbh->errstr()); $sth->execute($a) or die ($dbh->errstr()); my $b = $sth->fetchrow_array(); print qq(Name:$b missing\n); } }