Re: Perl DBI->Connect: how to detect a a lost connection
- From: rob.dixon@xxxxxxx (Rob Dixon)
- Date: Mon, 21 Jul 2008 00:44:46 +0100
Ravi Malghan wrote:
Hi: I have a script which connects to a database when it starts up
$dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$host;port=$port;",
"$username", "$password", {AutoCommit => 1});
followed by a while loop which runs a query for this connection at 60 second
intervals. If the database goes down for some reason, I want the script to
try reconnecting to the database. How do I figure out within the while look
if the database connection is still valid. If tried using the $dbh variable
(if ($dbh)then connection is fin. else connection is bad). That doesn't seem
to work. How do I figure out if the $dbh connection has been lost within the
while loop?
I suggest you connect to the database every time around the loop instead of just
once before it. If you use the connect_cached method instead of connect then the
connection will be verified and used again if it is still valid.
HTH,
Rob
.
- Follow-Ups:
- RE: Perl DBI->Connect: how to detect a a lost connection
- From: Stewart Anderson
- RE: Perl DBI->Connect: how to detect a a lost connection
- References:
- Perl DBI->Connect: how to detect a a lost connection
- From: Ravi Malghan
- Perl DBI->Connect: how to detect a a lost connection
- Prev by Date: Re: Perl DBI->Connect: how to detect a a lost connection
- Next by Date: how to convert data available from excel to hash?
- Previous by thread: Re: Perl DBI->Connect: how to detect a a lost connection
- Next by thread: RE: Perl DBI->Connect: how to detect a a lost connection
- Index(es):
Relevant Pages
|