in reply to A Database Connection Question

Have you looked at what the DBI documentation has to say about the word "connected"?

Also, if the connection to the database fails, I would simply use the RaiseError attribute to find out:

my $retries = 5; my $dbh; while( !$dbh and $retries --> 0 ) { my $connected = eval { $dbh DBI->connect( $dsn, $user, $pass, { RaiseError => 1, Prin +tError => 0 ); 1 }; if( !$connected ) { warn "Couldn't connect to $dsn: $@; $retries retries left."; } else { last; }; }; if( $retries == 0 ) { die "Couldn't connect to $dsn after five (re)tries"; };

Replies are listed 'Best First'.
Re^2: A Database Connection Question
by ChiloUK (Initiate) on Oct 08, 2015 at 16:50 UTC
    Many Thanks. I figured it out like this... while ( $switch == 0 ) { $switch = 1; $oDbc = DBI->connect("dbi:Informix:$sDatabase",'','' ) or $switch = 0; if (!$switch) { sleep 60; $counter++; } if ($counter == 120) { exit(0); } }