使用C#在Dynamics CRM中分配托管内存失败
问题描述:
我在Dynamics CRM中有1,072,369
联系人记录。我需要检索它们然后进行操作。现在,虽然检索我遇到以下异常使用C#在Dynamics CRM中分配托管内存失败
未能分配1073741824字节的托管内存缓冲区。可用内存量可能很低。
我增加了10分钟的时间跨度,但没有运气。
我正在寻求你的友善建议/帮助解决它。以下是我的代码片段。
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);
答
你有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