[Zope] Checking the state of a database connection
Hannu Krosing
hannu@tm.ee
Thu, 27 Jan 2000 14:32:20 +0200
Andreas wrote:
>
> "Daniel G. Rusch" wrote:
> > Try this, where Database is the name of your database object
> > <dtml-if "Database.connected()">
> > Yes
> > <dtml-else>
> > No
> > </dtml-if>
> I use ZPyGreSQLDA. The function connected() returns the
> value self._v_connected (DateTime of last connect call)
> of the Connection object.
> So if the SQL server crashes while Zope is still working
> the result of connected() is still 'true' although
> a query will fail :-(
I have modified UserDB to just do close/open on the connection if the
query fails.
You could do something similar - by doing a dummy query (like "select 1")
and checking if it succeeds.
--------
Hannu