Ken Foskey wrote: > On Wed, 2008-05-21 at 23:53 +1000, Ken Foskey wrote: >> I have a program that will run literally for days and days. It monitors >> logs by file tail. Problem is that I think the DBI is causing problems. >> It is constantly connecting and reconnecting to DB2 for every >> transaction. > > The original did not make much sense reading it back. > > I want to redesign the application to have an open connection > permanently. Problem is that I don't trust it, what happens if DB2 is > shutdown for instance. I have to recover the connection. Problem is I > cannot figure out how to check the connection is still OK without > calling something an have it fail. > > What I would like to do is replace my connect subroutine with a grab a > cached DBI handle, check it is still connected and if it is not > 'actually' connected, ie crashed, then reconnect it an return the new > DBI handle. > > Anyone know of a way to tell that a handle is still valid?
Any database operation will tell you whether the handle is still valid. I suggest you do a SELECT on one of your chosen database's system tables. In SQLite, for example, you could write "SELECT * FROM sqlite_master" and a success would indicate that the database is on line. It might be nice to make sure that the tables you're going to access are in the list of those that the database knows about. In SQLite you would execute "SELECT name FROM sqlite_master WHERE type = 'table'" and check that the names of your tables are in the list. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/