【问题标题】:Failed to allocate managed memory in Dynamics CRM using C#无法使用 C# 在 Dynamics CRM 中分配托管内存
【发布时间】:2016-02-22 11:25:25
【问题描述】:

我在 Dynamics CRM 中有 1,072,369 联系人记录。我需要检索它们然后进行操作。现在,在检索时我遇到了以下异常

未能分配 1073741824 字节的托管内存缓冲区。可用内存量可能很低。

我将其时间跨度增加到 10 分钟,但没有运气。

我正在寻求您的建议/帮助来解决它。以下是我的代码 sn-p。

ColumnSet col = new ColumnSet();
col.AddColumns("new_name", "accountid", "contactid");

                //get Related Record
                QueryExpression qe = new QueryExpression
                {
                    EntityName = entity,
                    ColumnSet = col,
                    Criteria = new FilterExpression
                    {
                        Conditions = { 
                        new ConditionExpression("accountid",ConditionOperator.NotNull),
                        new ConditionExpression("statecode",ConditionOperator.Equal,0)
                    }
                    }
                };

                EntityCollection ec = sp.RetrieveMultiple(qe);

【问题讨论】:

    标签: c# dynamics-crm-2011 contact


    【解决方案1】:

    你有1,072,369,所以我建议你批量检索这些记录。如果对检索记录有帮助,可以试试下面这段代码。

                QueryExpression qe = new QueryExpression
                {
                    EntityName = entity,
                    ColumnSet = col,
                    Criteria = new FilterExpression
                    {
                        Conditions = { 
                        new ConditionExpression("accountid",ConditionOperator.NotNull),
                        new ConditionExpression("statecode",ConditionOperator.Equal,0)
                    }
                    }
                };
    
                qe.PageInfo = new PagingInfo();
                qe.PageInfo.PagingCookie = null;
                qe.PageInfo.PageNumber = 1;
                qe.PageInfo.Count = 500;
    
    while (true)
                {
                    EntityCollection results= sp.RetrieveMultiple(qe);
                    if (results.Entities != null)
                    {
    
                    }
    
                    // Check for more records, if it returns true.
                    if (results.MoreRecords)
                    {
                        Console.WriteLine("\n****************\nPage number {0}\n****************", pagequery.PageInfo.PageNumber);
                        Console.WriteLine("#\tAccount Name\t\tEmail Address");
    
                        // Increment the page number to retrieve the next page.
                        pagequery.PageInfo.PageNumber++;
    
                        // Set the paging cookie to the paging cookie returned from current results.
                        pagequery.PageInfo.PagingCookie = results.PagingCookie;
                    }
                    else
                    {
                        // If no more records are in the result nodes, exit the loop.
                        break;
                    }
                }
    

    请参阅此处了解更多详情:

    https://msdn.microsoft.com/en-us/library/gg327917.aspxPage large result sets with QueryExpression

    PAGING QUERIES IN DYNAMICS CRM 2011

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-08
      • 2016-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-12
      • 2021-12-28
      相关资源
      最近更新 更多