I'd start by adding the argument { RaiseError => 1, PrintError => 0 } to the call to connect. It says it hasn't executed the statement, so it stands to reason it returned an error you didn't check. The above will cause subsequent errors to thrown an exception.