2009-08-18 284 views
0

当我运行数据库查询即时经常收到此为什么数据库会超时?

System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. 
Generated: Tue, 18 Aug 2009 08:05:39 GMT 

System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. 
    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) 
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) 
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) 
    at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) 
    at System.Data.SqlClient.SqlDataReader.ConsumeMetaData() 
    at System.Data.SqlClient.SqlDataReader.get_MetaData() 
    at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) 
    at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) 
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) 
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) 
    at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) 
    at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) 
    at System.Data.Common.DbCommand.ExecuteReader() 
    at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult) 
    at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries) 
    at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) 
    at System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() 
    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) 
    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) 
    at System.Data.Linq.Provider.BindingList.Create[T](DataContext context, IEnumerable`1 sequence) 
    at System.Data.Linq.DataQuery`1.GetNewBindingList() 
    at System.Data.Linq.DataQuery`1.System.ComponentModel.IListSource.GetList() 
    at System.Windows.Forms.CurrencyManager.SetDataSource(Object dataSource) 
    at System.Windows.Forms.BindingContext.EnsureListManager(Object dataSource, String dataMember) 
    at System.Windows.Forms.BindingContext.get_Item(Object dataSource) 
    at PlexityHide.GTP.TimeItemDataConnect.Wire() 
    at PlexityHide.GTP.TimeItemDataConnect.UpdateDataSource(IListSource aDataSource, String aDataMember, Layer aLayer) 
    at PlexityHide.GTP.TimeItemDataConnect.set_DataSource(Object value) 
    at PlexityHide.GTP.Layer.set_DataSource(Object value) 
    at WebSchedule._Default.Grid_OnEachListItemWhenDataBound_GridNode(Object GTPComponent, EachListItemWhenDataBoundArgs e) in C:\MyDev\WebSchedule\Schedule.aspx.cs:line 503 
    at PlexityHide.GTP.Grid.NodeChangedInDS(GridNode aNode) 
    at PlexityHide.GTP.NodeDataConnect.UpdateRowContent(Int32 index) 
    at PlexityHide.GTP.NodeDataConnect.EnsureBindUpToDate() 
    at PlexityHide.GTP.GridNodes.get_Count() 
    at PlexityHide.GTP.GridStructure.get_FirstVisibleNode() 
    at PlexityHide.GTP.Gantt.set_TurnOffAllCollisionDetect(Boolean value) 
    at PlexityHide.GTP.WEB.Gantt_ASP.OnPreRender(EventArgs e) 
    at System.Web.UI.Control.PreRenderRecursiveInternal() 
    at System.Web.UI.Control.PreRenderRecursiveInternal() 
    at System.Web.UI.BasePartialCachingControl.PreRenderRecursiveInternal() 
    at System.Web.UI.Control.PreRenderRecursiveInternal() 
    at System.Web.UI.Control.PreRenderRecursiveInternal() 
    at System.Web.UI.Control.PreRenderRecursiveInternal() 
    at System.Web.UI.Control.PreRenderRecursiveInternal() 
    at System.Web.UI.Control.PreRenderRecursiveInternal() 
    at System.Web.UI.Control.PreRenderRecursiveInternal() 
    at System.Web.UI.Control.PreRenderRecursiveInternal() 
    at System.Web.UI.Control.PreRenderRecursiveInternal() 
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
    --- End of inner exception stack trace --- 
    at System.Web.UI.Page.HandleError(Exception e) 
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
    at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
    at System.Web.UI.Page.ProcessRequest() 
    at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) 
    at System.Web.UI.Page.ProcessRequest(HttpContext context) 
    at ASP.schedule_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\13c4fe72\f906a8a8\App_Web_schedule.aspx.cdcab7d2.nhap4sin.0.cs:line 0 
    at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

可以通过它,在任何时间去到数据库连接的数量造成的? 有问题的页面会调用甘特图并使用每个特定合同的计划表中的数据填充它。发生了什么事情是,如果说有10人在拨打电话的同时发生超时,我将发生超时

+0

这是一个有多个用户的开发机器吗?你有没有在SQL方面对此进行分析?挂起时执行的SQL语句是什么? – 2009-08-18 14:12:23

+0

可能是数据库中的死锁,或者会是一个不同的异常? – ChrisW 2009-08-18 14:14:50

回答

3

您尝试执行的工作需要比默认超时时间更长的时间。您的查询运行速度太慢。它可能是这个查询,另一个查询减慢其他所有人,更新阻塞或许多原因。

0

可能你的陈述花费的时间太长。如果它只发生在多个用户身上,请查找可能会冻结资源的锁定。如果可能的话,使用“with(nolock)”。

0

检查在查询分析器中运行相同查询时需要多长时间。

查看查询计划。

使用事件探查器来检查是否有多个连接和所需的存储过程的时间。

在ADO.NET中检查命令超时。

0

这是客户端超时,所以如果数据库被大量使用(很多连接/大型查询)并且无法在指定的时间内响应,那么客户端最终会抛出异常。

尝试切入查询超时,或查看Profiler以优化查询。

9

有可能您的查询太长时间了。另一个很可能的原因是,只要完成了连接,就不会关闭连接,这会将连接释放到连接池中。

一般而言,您应该尽可能晚地获得连接,并尽早使用using声明来释放它们,以避免这种情况。如果你没有明确地关闭连接(即使面对异常),你可以将自己置于垃圾收集器和终结器的控制之下,以将连接返回到池中。

如果您认为您真的与长时间运行的查询有许多活动连接,您应该增加连接池中的连接数。如果您认为这是实际查询本身超时(即花费的时间超过您允许的时间),那么您应该增加命令或连接的超时时间。

0

不能看到您的查询或数据结构,我们只能提供什么可能导致您的超时猜测。在大多数情况下,查询速度会变慢。增加连接的超时时间可以解决超时问题,但通常最好修复查询。另一个需要注意的是查询所针对的表的索引。如果你的查询中有很多连接,那么你的索引应该包含你加入的字段。

0

以我的经验,它几乎总是查询。

在查询分析器或Management Studio中打开查询并查找预计的执行计划。我的经验法则是经常执行的查询的成本应低于1.00。如果它开始超过2.00,你会看到问题。 (当然,这是我的网站特有的,还有其他几个问题......)。

如果您的查询成本已经很低,请运行Profiler以查看还有哪些命令正在服务器上。然后开始分析这些查询以找到昂贵的查询。

如果它往往在一天的某些时间发生,检查这些:

  • 是备份进程在运行,并采取长于正常?
  • 是否有计划运行的阻塞(错误查询)?
  • 你是否用连接压倒了它?特别是在运行几个小时后,您可能会在连接管理中出现连接断开问题。
0

你正在使用什么隔离级别?

您使用连接池吗?

如果可以进行脏读,请确保您的隔离级别是uncommited读取。

+0

没有即时消息不使用连接池 – kevinw 2009-08-18 15:15:09

+0

您的超时设置为? 检查连接和命令 http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout.aspx http://msdn.microsoft.com/en-us/库/ system.data.sqlclient.sqlconnection.connectiontimeout.aspx – Keibosh 2009-08-19 16:16:23

相关问题