Hello all,
I've searched perlmonks and cpan and the perl cookbook, now I'm here asking. I successfully trap errors from my 'prepare' statement, but I'm having trouble trapping error messages from my 'connect' statement. My script runs overnight, connecting to an Oracle db, but if the db is down, I would like to trap a message when the connection fails. I will attach my existing code. Oh, I also implemented the attributes of '{RaiseError=>1,AutoCommit=>0}' but I still can't acheive what I want. Thank you in advance for all help.
# connection to database
my $dbh = DBI->connect("dbi:Oracle:CSCD001", "user", "password",{Raise
+Error=>1,AutoCommit=>0});
# new code to catch DB return error
$dbh->{RaiseError}=0;
my $sth = $dbh->prepare("Select $fields From $table Where exe_c = 'N'
+AND rownum < 151 ");
$sth->execute();
# new code to catch DB return error
print BATCH $dbh->errstr."\n";
@results{@fields} = ();
$sth->bind_columns(map{\$results{$_} } @fields);
# generates DBI log file
DBI->trace( 2 , './dbi_trace.txt');
while($sth->fetch()) {
# prints to screen to view process running
print "$results{batch_line} <$results{rowid}>\n";