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

几天前我注意到我的Web应用程序给了我一个exception超时的sql过期。

我清理了几个存储过程,需要更多的CPU并重新启动SQL Server服务,我的应用程序开始工作,因为它是在快速和没有任何延迟之前。 三四个小时后我再次检查它,我无法加载页面,而不是它给我的exception超时到期。 我检查了服务器CPU是好的一切看起来很好。 我在同一个IIS 7下有一些其他网站,它们运行良好,没有任何例外。 我再次重新启动SQL Server服务,我的应用程序再次恢复正常。 我认为它看起来像SQL服务器数据库上的问题,但我不知道如何解决它。

因此,每当我遇到exception时,我只是重启sql服务,但当然这不是最好的方法。 请帮我解决这个问题。

这是我得到的一个例外。

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

好吧,首先,它是“UpdateHitCounter”函数,它是近端导致问题的,但你不知道这是一个原因还是一个影响。 您的查询超出了分配完成的配置时间。

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

如果您想采用更加严格的分类方法,则可以限制探查器仅记录完成时间超过x秒的查询,无论您认为x应该是什么。 如果没有任何显示,我通常从5开始并从那里开始工作。 这是该主题的入门读物。

识别长时间运行的查询后,在本地副本中执行它们并检查执行计划。 这是一本入门书,但要开始寻找“表扫描”。

最终,您的数据库不是最理想的,或者您的硬件不符合流量。 这几乎可以肯定是第一个,这两种方法应该让你顺利。

听起来像是漏洞的行为。 在不知道你的一般架构的情况下,我不能说出什么样的泄漏,但我可能会建议查看你所有的表,看看是否有任何东西似乎比你期望的更多行。

您也可以在SQL Management Studio中手动运行您的sprocs,看看哪些花了很长时间 – 也许您正在运行一个算法,其运行时间随着正常运行时间的增加而增加。