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 I have seen in other implementations. using a simple "select sysdate from dual" (which is very fast since it does not query any table) type of check and trapping the response to see if it is connected. But, that will take more instructions than simply re-connecting, don't know how much of a performance thing it will be versus the "select/check", Though if Rob suggests a re-connect, he might already have been down that alley. Stu -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Information in this email including any attachments may be privileged, confidential and is intended exclusively for the addressee. The views expressed may not be official policy, but the personal views of the originator. If you have received it in error, please notify the sender by return e-mail and delete it from your system. You should not reproduce, distribute, store, retransmit, use or disclose its contents to anyone. Please note we reserve the right to monitor all e-mail communication through our internal and external networks. SKY and the SKY marks are trade marks of British Sky Broadcasting Group plc and are used under licence. British Sky Broadcasting Limited (Registration No. 2906991), Sky Interactive Limited (Registration No. 3554332), Sky-In-Home Service Limited (Registration No. 2067075) and Sky Subscribers Services Limited (Registration No. 2340150) are direct or indirect subsidiaries of British Sky Broadcasting Group plc (Registration No. 2247735). All of the companies mentioned in this paragraph are incorporated in England and Wales and share the same registered office at Grant Way, Isleworth, Middlesex TW7 5QD. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/