Added a check if the database is connected