System.Data.SqlClient.SqlException:Timeoutexpired几天前,我注意到我的网络应用程序给我一个异常sqlexpiredfortimeout。我清理了一些需要更多CPU的存储过程并重新启动了SQLServer服务,我的应用程序开始运行,因为它速度很快而且没有任何延迟。三四个小时后我再次检查它,我无法加载页面,而是给我异常超时已过期。我检查了服务器CPU没问题,一切看起来都很好。我在同一个IIS7下还有一些其他网站,它们工作正常,没有任何例外。我重新启动了SQLServer服务,我的应用程序又恢复正常了。我认为它看起来像是SQLServer数据库上的问题,但我不知道如何修复它。所以每当我遇到异常时,我只是重新启动sql服务,但这当然不是最好的方法。请帮我解决这个问题。这是我得到的一个例外。消息:抛出了“System.Web.HttpUnhandledException”类型的异常。来源:System.Web内部异常:System.Data.UpdateException:更新条目时出错。有关详细信息,请参阅内部异常。—>System.Data.SqlClient.SqlException:超时已过。在操作完成之前超时期限已过或服务器未响应。该语句已终止。System.Data.SqlClient.SqlConnection.OnError(SqlExceptionexception,BooleanbreakConnection)atSystem.Data.SqlClient.SqlInternalConnection.OnError(SqlExceptionexception,BooleanbreakConnection)onSysteminSystem.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStatejObject)状态System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReaderds,RunBehaviorrunBehavior,StringresetOptionsString)onSystem.Data.SqlClient.Data.SqlClient.TdsParser.Run(RunBehaviorrunBehavior,SqlCommandcmdHandler,SqlDataTmpledsStateserSetdataStream.Data.ResultCopy中的对象)SqlClient.SqlCommand.RunExecuteReader(CommandBehaviorcmdBehavior,RunBehaviorrunBehavior,BooleanreturnStream,Stringmethod,DbAsyncResultresult)onSystem.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehaviorcmdBehavior,RunBehaviorreStraviorcmdBehavior,RunBooleanasync).SqlCommand.InternalExecuteNonQuery(DbAsyncResult结果,System.Data.SqlClient.SqlCommand.ExecuteNonQuery()中的StrSystemName,布尔sendToPipe)在System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator转换器,EntityConnection连接2,字典标识符值,列表1个生成值)。Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManagerstateManager,IEntityAdapter适配器)-内部异常堆栈跟踪结束-在System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManagerstateManager,IEntityAdapter适配器)在System.数据System.Data.Objects.ObjectContext.SaveChanges(BooleanacceptChangesDuringSave)在.EntityClient.EntityAdapter.Update(IEntityStateManagerentityCache),在System.Data.Objects.ObjectContext.SaveChanges()在BCSCDomain.Domain.DataLayer.OtherDataLayer。UpdateCitnd(Int32hlistid,Int32hcounterid)在BuyCarandSellCar.UsedCarProfilePage.HitCounter()在BuyCarandSellCar.UsedCarProfilePage.Page_Load(Objectsender,EventArgse)在System.Web.Util.CalliEventHandlerDelegateProxy在SSystem.Web.UI.Control.OnLoad。系统中的回调(对象发送者,EventArgse).Control.LoadRecursive()(BooleanincludeStagesBeforeAsyncPoint,BooleanincludeStagesAfterAsyncPoint)堆栈跟踪:在System.Web.UI.Page.HandleError(Exceptione)在System.Web.UI.Page.ProcessRequest()在SystemWebSystem.Web.UI.Page.ProcessRequest(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)。UI.Page.ProcessRequestWithNoAssert(HttpContextContext)atSystem.Web.UI.Page.ProcessRequest(HttpContextContext)atASP.usedcarlistings_profilepage_aspx.ProcessRequest(HttpContextContext)inc:\Windows\Microsoft.NETFrameworkv2.0.50727临时ASP。NET文件根79794658835d6695App_Web_kmrmpdbb.16.cs:System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值和同步完成)在System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecution.IExecution(Step)嗯,首先,它是“UpdateHitCounter”函数,它是导致问题的近端,但您不知道它是原因还是结果。您的查询超出了配置的完成时间。每当您的数据库性能不佳时,您可以在其上运行的一种广泛方法是将SqlProfiler附加到它,然后对结果执行索引调整向导。如果你想采用更严格的分类方法,你可以限制探查器只记录完成时间超过x秒的查询,无论你认为x应该是什么。如果什么都没有出现,我通常从5点开始工作。这是该主题的入门读物。确定长时间运行的查询后,在本地副本中执行它们并检查执行计划。这是一本入门书,但要开始寻找“表格扫描”。最终,您的数据库不是最理想的,或者您的硬件无法满足流量要求。这几乎肯定是第一个,这两种方法应该可以让你继续。听起来像一个错误的行为。在不知道您的一般架构的情况下,我不能说这是哪种泄漏,但我可能建议查看您所有的表,看看是否有任何东西的行数似乎比您预期的要多。您还可以在SQLManagementStudio中手动运行您的存储过程,看看哪些花费了很长时间——也许您正在运行一种算法,其运行时间随着正常运行时间的增加而增加。以上就是C#学习教程:System.Data.SqlClient.SqlException:Thetimeouthasexpired分享的所有内容,如果对大家有用,需要了解更多C#学习教程,希望大家多多关注——本文来自网络收集,不代表侵权,请点击右边联系管理员删除。如需转载请注明出处:
