implement automatic database reconnect