繁体   English   中英

System.Data.SqlClient.SqlException:超时已过期

[英]System.Data.SqlClient.SqlException: Timeout expired

几天前,我注意到给我sql异常超时的Web应用程序已过期。

我清理了一些占用更多CPU的存储过程,并重新启动了SQL Server服务,并且我的应用程序像往常一样快速且没有任何延迟地开始工作。 三四个小时后,我再次进行了检查,但无法加载页面,这超出了超时超时范围。 我检查了服务器CPU是否正常,一切看起来都很好。 我在同一IIS 7下有一些其他网站,它们运行良好,没有任何例外。 我再次重新启动了SQL Server服务,并且我的应用程序再次恢复正常。 而且我认为这看起来像是SQL Server数据库上的问题,但是我不确定如何解决它。

因此,每次遇到异常时,我都只是重新启动sql服务,但这当然不是最好的方法。 请帮助我解决此问题。

这是我遇到的例外之一。

消息:引发了'System.Web.HttpUnhandledException'类型的异常。 源:System.Web内部异常:System.Data.UpdateException:更新条目时发生错误。 有关详细信息,请参见InnerException。 ---> System.Data.SqlClient.SqlException:超时已过期。 在操作完成之前超时或服务器没有响应。 该语句已终止。 在系统上System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,布尔breakConnection)在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)在System.Data.SqlClient.SqlConnection.OnError(SqlException异常,Boolean breakConnection) .Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)位于System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior resetBehavior,at。 SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,Boolean异步)位于System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String方法,DbAsyncResultClient。 SqlCommand.InternalExecuteNonQuery(DbAsyncResult结果,Str 在System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(System.Data.SqlClient.SqlCommand.ExecuteNonQuery()处的methodName,布尔型sendToPipe)在系统处的System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator,EntityConnection connection,Dictionary 2 identifierValues, List 1 generateValues)中。 Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager,IEntityAdapter适配器)-内部异常堆栈跟踪的结尾--在System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager,IEntityAdapter适配器),位于BCSCDomain.Domain.DataLayer.OtherDataLayer处System.Data.Objects.ObjectContext.SaveChanges()处System.Data.Objects.ObjectContext.SaveChanges(Boolean acceptChangesDuringSave)处System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)。在S的BuyCarandSellCar.UsedCarProfilePage.HitCounter()处的UpdateHitCounter(Int32 hlistid,Int32 hcounterid)在S处的BuyCarandSellCar.UsedCarProfilePage.Page_Load(Object sender,EventArgs e) ystem.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,EventArgs e)在System.Web.UI.Control.OnLoad( System.Web.UI.Page.ProcessRequestMain(System.Web.UI.Control.LoadRecursive()处的EventArgs e)(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)堆栈跟踪:位于System.Web.UI.Page.HandleError(Exception e) System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)(System.Web.UI.Page.ProcessRequestMain(System.Web.UI.Page.ProcessRequest(Boolean) System.Web.UI.Page.ProcessRequest(HttpContext上下文)处的UI.Page.ProcessRequestWithNoAssert(HttpContext上下文)位于c:\\ Windows \\ Microsoft.NET \\ Framework \\ v2.0.50727 \\ Temporary中ASP.usedcarlistings_profilepage_aspx.ProcessRequest(HttpContext上下文) ASP.NET文件\\ root \\ 79 794658 \\ 835d6695 \\ App_Web_kmrmpdbb.16.cs:System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()位于System.Web.HttpApplication.ExecuteStep的第0行

好吧,首先,是“ UpdateHitCounter”函数在近端引起了问题,但是您不知道这是原因还是结果。 您的查询超出了分配的完成时间。

每当您的数据库性能不佳时,可以在其上运行广泛的方法是将Sql Profiler附加到该数据库,然后对结果执行索引优化向导。

如果您想采用一种更严格的分类方法,则可以限制分析器仅记录完成时间超过x秒的查询,无论您认为x应该是什么。 我通常从5开始,如果没有任何反应,则从那里开始进行研究。 是该主题的入门。

一旦确定了长时间运行的查询,请在本地副本中执行它们并检查执行计划。 是一个入门指南,但首先要寻找“表扫描”。

最终,您的数据库不是最理想的,或者您的硬件无法承受流量。 几乎可以肯定这是第一个,这两种方法应该可以助您一臂之力。

听起来像是漏气的行为。 在不了解您的总体体系结构的情况下,我无法说出哪种泄漏,但是我建议您查看一下所有表,看看是否有什么行比您期望的多。

您还可以在SQL Management Studio中手动运行存储过程,并查看哪些存储过程花费的时间太长-也许您正在运行的算法的运行时间随正常运行时间而增加。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM