Although helpful and fixing some errors in the OPs code, the answer provided by @Santiago Squarzon does give the same error after about 22000 results (in my case at least). Here is some guidance at Microsoft Learn for working with large datasets. Hope this helps