add check if sql is closed