I need the program to continue even if there was an error in connecting to the database. So far with many tries, I have not been able to prevent program from terminating when there is an error in connecting to the database. The program works fine with correct password.
(Perl script is given at the end)
If I use 0 for RaiseError, I get following error:
-------------------------------------------------
DBI connect('acd1','intcustapp',...) failed: at tt_testdbi.pl line 12
Uncaught exception from user code:
Uncaught exception from user code:
Can't call method "prepare" on an undefined value at tt_testdbi.pl line 22.
eval {...} called at tt_testdbi.pl line 5
If I use 1 for RaiseError, I get:
---------------------------------
Uncaught exception from user code:
Uncaught exception from user code:
DBI connect('acd1','intcustapp',...) failed: at tt_testdbi.pl line 12
Carp::croak('DBI connect(\'acd1\',\'intcustapp\',...) failed: ') called at C:/Perl/site/lib/DBI.pm line 580
DBI::__ANON__(undef, undef) called at C:/Perl/site/lib/DBI.pm line 630
DBI::connect('DBI', 'dbi:Oracle:acd1', 'intcustapp', 'intcustapp2', 'HASH(0x183ef44)') called at tt_testdbi.pl line 12
eval {...} called at tt_testdbi.pl line 5
Program Code:
-------------
use strict;
use diagnostics;
use DBI;
eval { #Cath any kind of failures
my $DB = "Oracle"; # Database
my $DB_SID = "acd1"; # SID
my $DB_USER = "intcustapp"; # Database user
my $DB_PASS = "invalidpwd"; # Database password
my $dbh = DBI->connect( "dbi:$DB:$DB_SID",
$DB_USER,
$DB_PASS,
{
RaiseError => 1,
AutoCommit => 0
}
);
my $sql = qq{ SELECT sysdate, user FROM dual };
my $sth = $dbh->prepare( $sql );
$sth->execute();
my( $today_dt, $user_name );
$sth->bind_columns( undef, \$today_dt, \$user_name );
while( $sth->fetch() ) {
print "$today_dt, $user_name\n";
}
$sth->finish();
$dbh->disconnect();
};
if ($@ =~ /invalid /) # if error message has the word invalid
{
print $@;
}
elsif ($@) # some other error occurred
{
die $@;
};
Thanks
Dhawal
(Perl script is given at the end)
If I use 0 for RaiseError, I get following error:
-------------------------------------------------
DBI connect('acd1','intcustapp',...) failed: at tt_testdbi.pl line 12
Uncaught exception from user code:
Uncaught exception from user code:
Can't call method "prepare" on an undefined value at tt_testdbi.pl line 22.
eval {...} called at tt_testdbi.pl line 5
If I use 1 for RaiseError, I get:
---------------------------------
Uncaught exception from user code:
Uncaught exception from user code:
DBI connect('acd1','intcustapp',...) failed: at tt_testdbi.pl line 12
Carp::croak('DBI connect(\'acd1\',\'intcustapp\',...) failed: ') called at C:/Perl/site/lib/DBI.pm line 580
DBI::__ANON__(undef, undef) called at C:/Perl/site/lib/DBI.pm line 630
DBI::connect('DBI', 'dbi:Oracle:acd1', 'intcustapp', 'intcustapp2', 'HASH(0x183ef44)') called at tt_testdbi.pl line 12
eval {...} called at tt_testdbi.pl line 5
Program Code:
-------------
use strict;
use diagnostics;
use DBI;
eval { #Cath any kind of failures
my $DB = "Oracle"; # Database
my $DB_SID = "acd1"; # SID
my $DB_USER = "intcustapp"; # Database user
my $DB_PASS = "invalidpwd"; # Database password
my $dbh = DBI->connect( "dbi:$DB:$DB_SID",
$DB_USER,
$DB_PASS,
{
RaiseError => 1,
AutoCommit => 0
}
);
my $sql = qq{ SELECT sysdate, user FROM dual };
my $sth = $dbh->prepare( $sql );
$sth->execute();
my( $today_dt, $user_name );
$sth->bind_columns( undef, \$today_dt, \$user_name );
while( $sth->fetch() ) {
print "$today_dt, $user_name\n";
}
$sth->finish();
$dbh->disconnect();
};
if ($@ =~ /invalid /) # if error message has the word invalid
{
print $@;
}
elsif ($@) # some other error occurred
{
die $@;
};
Thanks
Dhawal