Attempt to reconnect to database if connection is closed.