Added error check on DB connection