add check for open database connection