2009-08-18 53 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

相關問題