Normal operation procedure is to open and close the connection every time
you communicate with the database. If you work like that, you will get an
error if it is not possible to establish a connection. In any case, you'll
receive an error if the connection is broken, and you can act on that, for
instance by popping up a message, logging the error, or storing the failed
query in a buffer to retry later.
Regards,
Wiebe.