Database: auto-reconnect if the connection goes invalid