Ensure connection exists before executing batch queries