Added error handler to check the database connection