Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to test the status of a database connection? 1

Status
Not open for further replies.

sloppyhack

Technical User
Apr 17, 2001
111
US
I am trying to do some cleanup of database connections when a GUI window is closed or destoyed. If the database handle is currently "connected" I want to rollback all transactions associated with database handle and disconnect. If I try to rollback and disconnect a database handle that is not connected...I get all sorts of error messages.

Anyone know how to get the current status of database handle? Connected or not? I can't seem to find any info in the DBI documentation. I'm sure it's something simple.

Cheers,

Sloppyhack
 
I know if nothing specific or can find anything in the DBI documentation either:


I would suggest trying two things. One being the ->can method.

cpan said:
can

$is_implemented = $h->can($method_name);

Returns true if $method_name is implemented by the driver or a default method is provided by the DBI. It returns false where a driver hasn't implemented a method and the default method is provided by the DBI is just an empty stub.

The module test scripts 02dbidrv.t and 02handle.t have examples of its use.

Alternatively, just wrap you're trying to do in an eval to trap the errors that are thrown. If an error is thrown, than just assume that the disconnect procedure has already been done. QED.

Goodluck
 
Couldn't get that to work. We have a module that is controlling the connections. We just added a "status" method to it to return the state of the connection as "defined" or "undefined".

Cheers,

Sloppyhack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top