in reply to DBI Error

As btrott above, use $sth->finish to close your cursor, You could also use :
my $dbh = DBI->connect('dsn', 'uid', 'pwd', {RaiseError => 1});
to raise your errors if your version of DBI is up to date enough.