我正在运行一个 ASP.NET 网页页面,该页面在初始加载时会从 SQL 服务器中提取项目列表。此查询在一秒钟左右运行并在 2 秒内加载页面。回报是大约 1000 条记录,给予或接受。我正在从 Service Manager SQL 数据库中提取主机名以及其他一些信息。
在此页面中,我内置了一个搜索,它基本上运行完全相同的查询,但使用基于主机名的 LIKE 运行它。这将加载包含搜索查询一部分的所有主机名的同一页面。查询通常在一秒钟内在 SQL Management Studio 中运行,但加载页面需要更长的时间,有时甚至会超时。
我的问题是,为什么基于参数的搜索需要更长的时间,有时甚至会无缘无故地超时。是否可以采取任何措施来缓解此超时?以下是完整的错误。
“/”应用程序中的服务器错误。
The wait operation timed out
说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详情:
System.ComponentModel.Win32Exception: The wait operation timed out
Source Error:
Line 13: }
Line 14:
Line 15: var selectedData = db.Query(selectCommand, searchTerm);
Line 16:
Line 17:
Source File: c:\Users\u0149920\Documents\My Web Sites\AppSupport\servers\default.cshtml Line: 15
堆栈跟踪:
[Win32Exception (0x80004005): The wait operation timed out]
[SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1753346
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5295154
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +242
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1682
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +59
System.Data.SqlClient.SqlDataReader.get_MetaData() +90
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +365
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite) +1325
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +175
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +134
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +41
System.Data.Common.DbCommand.ExecuteReader() +12
WebMatrix.Data.<QueryInternal>d__0.MoveNext() +152
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +381
System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
WebMatrix.Data.Database.Query(String commandText, Object[] parameters) +103
ASP._Page_servers_default_cshtml.Execute() in c:\Users\u0149920\Documents\My Web Sites\AppSupport\servers\default.cshtml:15
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +69
System.Web.WebPages.WebPage.ExecutePageHierarchy() +151
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76
System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase httpContext) +114
版本信息:Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929