【发布时间】:2010-09-26 06:41:37
【问题描述】:
我有一个返回大约 590,000 条记录的动态查询。它第一次运行成功,但如果我再次运行它,我会不断收到System.OutOfMemoryException。发生这种情况的一些原因是什么?
错误发生在这里:
public static DataSet GetDataSet(string databaseName,string
storedProcedureName,params object[] parameters)
{
//Creates blank dataset
DataSet ds = null;
try
{
//Creates database
Database db = DatabaseFactory.CreateDatabase(databaseName);
//Creates command to execute
DbCommand dbCommand = db.GetStoredProcCommand(storedProcedureName);
dbCommand.CommandTimeout = COMMAND_TIMEOUT;
//Returns the list of SQL parameters associated with that stored proecdure
db.DiscoverParameters(dbCommand);
int i = 1;
//Loop through the list of parameters and set the values
foreach (object parameter in parameters)
{
dbCommand.Parameters[i++].Value = parameter;
}
//Retrieve dataset and set to ds
ds = db.ExecuteDataSet(dbCommand);
}
//Check for exceptions
catch (SqlException sqle)
{
throw sqle;
}
catch (Exception e)
{
throw e; // Error is thrown here.
}
//Returns dataset
return ds;
}
这是在按钮单击时运行的代码:
protected void btnSearchSBIDatabase_Click(object sender, EventArgs e)
{
LicenseSearch ls = new LicenseSearch();
DataTable dtSearchResults = new DataTable();
dtSearchResults = ls.Search();
Session["dtSearchResults"] = dtSearchResults;
Response.Redirect("~/FCCSearch/SearchResults.aspx");
}
else
lblResults.Visible = true;
}
【问题讨论】:
-
590K 行有点过分,你不觉得吗?
-
问题不只是你将DataTable存储在Session中,然后在重新查询时,你的Session变量和原始DataTable都在内存中吗?顺便说一句,不要调用
throw e;,调用throw;,否则你的堆栈跟踪会说catch处理程序生成了异常,而实际上它是包含代码。
标签: asp.net sql-server tsql