我正在尝试调试一个在我们的一个遗留系统中突然出现的问题。
这就是有问题的代码
DataSet content = new DataSet();
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmdSearchQuestionLibrary = db.GetStoredProcCommand("CUP_Reports_GetTrainerPerformanceReport");
db.AddInParameter(cmdSearchQuestionLibrary, "@PartnerID", DbType.Int64, partnerId);
db.AddInParameter(cmdSearchQuestionLibrary, "@StartDate", DbType.DateTime, dtStartDate);
db.AddInParameter(cmdSearchQuestionLibrary, "@EndDate", DbType.DateTime, dtEndDate);
db.AddInParameter(cmdSearchQuestionLibrary, "@TrainerId", DbType.Int32, trainerId);
db.AddInParameter(cmdSearchQuestionLibrary, "@AssessmentType", DbType.Int32, assessmentType);
content = db.ExecuteDataSet(cmdSearchQuestionLibrary);超时发生在db.ExecuteDataSet上。我在SQL Server事件探查器中对此进行了跟踪,并对同一数据库运行了相同的查询,返回数据所需的时间不到一秒。
如果我延长超时时间,我可以看到返回相同的数据需要超过一分钟的时间,这是不可接受的。
是不是我漏掉了什么?我想知道db.GetStoredProcCommand是否正在打开一个需要关闭的连接,而它只是在等待该连接关闭。
发布于 2013-10-29 23:07:33
在尝试了几种方法之后,最终的解决方案是将WITH Recompile添加到存储过程中。看起来DB持有的是一个糟糕的执行计划。
https://stackoverflow.com/questions/19658540
复制相似问题