Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: DB Error Handling Not Working

by poj (Priest)
on Aug 13, 2014 at 09:20 UTC ( #1097236=note: print w/ replies, xml ) Need Help??


in reply to DB Error Handling Not Working

Try with RaiseError and/or PrintError set.

my $dbh = DBI->connect("dbi:ODBC:$DSN",{RaiseError => 1, PrintError => + 1});
poj


Comment on Re: DB Error Handling Not Working
Select or Download Code
Re^2: DB Error Handling Not Working
by sowais (Sexton) on Aug 13, 2014 at 17:47 UTC

    Tried that but didn't work either. Trace showed that the error occurred but was again cleared by the 'disconnect' call.

      Sorry, the connection string should be DBI->connect($data_source, $username, $password, \%attr) so either use
      my $dbh = DBI->connect("DBI:ODBC:$DSN",'','', {RaiseError => 1, PrintError => 1}) or die (Error connecting " $DBI::errstr");
      or move the username/password out of the $DSN.
      poj

      Update : To get current date/time you could just use
      my ($now) = $dbh->selectrow_array('SELECT CURRENT_TIMESTAMP');

      sowais:

      If the error is cleared by the disconnect call, then pull the disconnect out of the block and put it after the end of the eval block. If you feel you need similar error checking for the disconnect, wrap that in its own eval block.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

        sorry, didn't realize i was logged out for the earlier post.. Tried that but eval didn't capture it. Against my better judgement I put in a 'die' statement next to the execute statement and that seems to work! I would prefer not to have an error handler within an error handler but unfortunately I've burned way too much time troubleshooting 'eval's failrue to capture the error.
        eval { $dbh = DBI->connect("dbi:ODBC:$DSN"); ... $sth->execute() or die "Execute Failed: $!"; $dbh->disconnect(); }; if($@) { print "DB Failure: $@"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1097236]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (15)
As of 2014-09-30 17:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (379 votes), past polls