Added check to get DB connection if it is closed