Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

How to Fetch large number of records using QueryExpression.

(0) ShareShare
ReportReport
Posted on by 10

Background:

I need to retrieve more than 800K record from an entity. After the record is fetched I need to send the record back as CSV file to caller for download. QueryExpression can have 20 or more attributes.

Web Application using c#. Its an API that fetch record and sends CSV file as response.

Action:

I connect to CRM and use QueryExpression to fetch the record. I use pagination to fetch more than 5K records. 

Issue:

  1. It takes around 30 sec to fetch 5K records, so for approx 800K records it takes around 1.5hour. I would like to accelerate the process and decrease the time., Is there a way to do so?
  2. When 500K records is fetched, I add it to the List. After certain number of records ( number not know but it's more then 300K records), I get error that reads "Failed to allocate a managed memory buffer of 67108864 bytes. The amount of available memory may be low."  How can i resolve this issue? When there is huge number of records being fetched at once, can anyone provide insights on it. 

I wanted to use Parallel For loop but the problem is, for pagination for QueryExpression, it depends on pagingcookies and pagenumber, so It is not feasible. 

I would be very thankful if someone could provide some insights to resolve 2 issues.

  • Haseeb Jamshed Profile Picture
    360 on at
    RE: How to Fetch large number of records using QueryExpression.

    Yeah, I was thinking with respect to SSIS Perspective, However You can still use Point #2 for your work.

    For Point # 1 - Have you tried to use Threading to process records?

  • Sabin Sharma Profile Picture
    10 on at
    RE: How to Fetch large number of records using QueryExpression.

    Hello haseeb,

    Are you talking about balance distributor in SSIS? I am using web application and Language is c#.

    Thank you for your insights, but it seems like you are talking about SSIS. Can you please provide more detail on your point 1 and 2 if it's not related with SSIS.

  • Haseeb Jamshed Profile Picture
    360 on at
    RE: How to Fetch large number of records using QueryExpression.

    Issue #1 - Use balance distributer.

    Issue #2 -

    1. Reduce CRM connection Batch Size.

    2. Check and change default buffer size and defaultbufferrowsize

     example: Set Default Buffer Size = Default size/4

     suppose row size = 10k then change to 2500

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,017 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,852 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans