Throw exception if the database is not connected when we try to query it.