【发布时间】:2011-01-26 06:39:17
【问题描述】:
我在从相当大的列表中检索项目时遇到问题。我可以快速轻松地从包含或多或少 50 个项目的小列表中检索项目,但是当我尝试从包含或多或少 4600 个项目的列表中检索项目时,sqlsever.exe 进程在请求期间会出现峰值,但是永远不会检索项目。如果已经设置了 Web 应用程序限制设置,那么它不可能是导致问题的原因。这是我最初用于检索项目的代码。它真的没有什么特别的。
using (SPSite site = new SPSite(siteUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists[uid.ToString()];
SPListItemCollection itemCollection = list.Items;
foreach (SPListItem i in itemCollection) //This is where the code stops responding
{
//Use list items
}
}
}
在那之后不起作用,我尝试了其他几种方法来从列表中检索项目。代码如下:
SPList list = web.Lists[uid.ToString()];
SPQuery query = new SPQuery();
query.Query = "";
query.QueryThrottleMode = SPQueryThrottleOption.Override;
SPListItemCollection itemCollection = list.GetItems(query);
//The code stops here
//I added this part for interest sake, i wanted to if it was the looping that caused the problem
//It seems the when you try to access properties of the item collection that the problem occurs
int itemCount = itemCollection.Count;
foreach (SPListItem i in itemCollection)
{
//Use list items
}
我也试过了:
SPList list = web.Lists[uid.ToString()];
SPListItemCollectionPosition pos;
DataTable dt = list.GetDataTable(new SPQuery(), SPListGetDataTableOptions.None, out pos); //The code stops responding here
foreach (DataRow i in dt.Rows)
{
//Use data rows
}
有谁知道是什么导致了这个问题?
提前谢谢你!
【问题讨论】:
标签: sql sql-server sharepoint sharepoint-2010 sql-server-2008-r2