SQL Server 2008 逾時已過期

SQL Server 2008 逾時已過期

我在 Stackoverflow 上問了下面的問題,但沒有得到任何答案,但是,有人建議我也在 serverfault 上問這個問題。希望有人可以提供幫助。

我最近將 ASP.Net MVC 3 Web 應用程式(用於資料持久性的實體框架 4.1)發佈到即時伺服器。應用程式位於一台 Web 伺服器上,資料庫 (SQL Server 2008) 位於另一台單獨的伺服器上。

網站僅上線幾天,點擊量很少,因此資料庫表中包含的記錄非常少(最多 10-20 條)。

我還將 ELMAH(ASP.NET 的錯誤日誌模組和處理程序)整合到網站中,並且我已經收到了一些以下錯誤的實例

System.Data.SqlClient.SqlException:逾時已過期。操作完成之前超時時間已過,或伺服器未回應。

下面顯示了 ELMAH 提供的完整詳細信息

System.Data.EntityException:底層提供者在開啟時失敗。 ---> System.Data.SqlClient.SqlException:逾時已過期。操作完成之前超時時間已過,或伺服器未回應。在System.Data.SqlClient.SqlInternalConnection.OnError(SqlException異常,布林breakConnection)在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()在System.Data.SqlClParient.TVolstateStateStateObject.Remoseral(Cjaljjstate)在Halstateal. .sqlclient.tdsparserstateObject.ReadSni(dbasyncresult asyncresult,tdsparserstateObject stateboct) ERT,布爾值和marscopable)在system.data。 SqlClient.TdsParser.Connect(ServerInfo serverInfo,SqlInternalConnectionTds connHandler,布爾ignoreSniOpenTimeout,Int64 timeExpire,布爾加密,布爾trustServerCert,布爾integratedSecurity)在System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,字串newPassword,布林ignoreSniOpenTimeout,超時, SqlConnection owningObject)在System.Data.SqlClient.SLoglInterfail.S. ,字元字串newPassword,布林重定向UserInstance,SqlConnection owningObject,SqlConnectionString連接選項,TimeoutTimer逾時)在System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(Sq) l連接owningObject,TimeoutTimer,SqlString超時,SqlString connection,Smq. 。 bConnection owningConnection)在System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection,DbConnectionPool池,DbConnectionOptions選項)在System.Data.ProviderBase.DbConnectionPool.CreateObject(Db) owningConnection” )在System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)在System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)在System.Data.ProviderBase。 .SqlConnection.Open() 處的DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) 。OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptsOperation, Boolean& closeStoreConnectionOnFailure) --- 內部異常堆疊.連接,字串異常代碼,字串嘗試操作,布林值& closeStoreConnectionOnFailure)在System.Data.EntityClient.EntityConnection.Open()在System.Data.Objects.ObjectContext.Ensure()在System.Data.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption) 在 System.Data.Objects.ObjectQuery 1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Collections.Generic.List1..ctor(IEnumerable 1 來源) System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary 2 參數) 在 System.Web.Mvc.ControllerContext controllerContext, IDictionary 2 參數) 在 System.Web.Mvc.ControllerActionInj.15__c15%。 b__12()在System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter過濾器,ActionExecutingContext preContext,Func 1過濾器,ActionDescriptor actionDescriptor,IDictionary`2參數)在System.Web.M.ControllerActionInvokeror,IDictionary`2參數)在System.Web.M.ControllerActionInvokeror,IDictionary`2參數)在System.Web.M.ControllerActionInvokeror,ID. actionName)1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable
2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary1 continuation) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList

發生此錯誤的情況是由於 SELECT 查詢造成的。這些選擇查詢非常簡單,即

從表中選擇 col1、col2、col3,其中 col1 = 1

正如我所說,資料庫中的資料非常少,因此查詢不會拉回 100 筆記錄。

我已經使用這兩種方法對此進行了一些研究網際網路堆疊溢位。有人建議增加dbContext 指令逾時然而,財產,我不明白為什麼我需要這樣做。是的,如果我要拉回大量記錄,但正如我所說,這些都很簡單選擇語句最多撤回 1-5 筆記錄。

我也知道開發人員需要專注於實體框架產生的 SQL,所以,我下載並運行了這個試用版http://www.datawizard.com為了查看為導致問題的實體框架 SELECT 查詢所建立的 SQL。同樣,探查器顯示這些查詢的語法非常簡單,所以我認為這不是問題。

我開始認為這可能與我的資料庫和 Web 應用程式位於不同的伺服器上有關,但是,我沒有想法!

如果有人可以幫助或建議我解決這個問題,我將不勝感激。

感謝大家。

答案1

若要消除用戶端或網路問題,請在啟用用戶端統計資料的管理工作室中執行產生的 SQL,並觀察執行查詢所需的執行時間和工作量。

您可以使用 GO 跟隨 SELECT 查詢來連續執行任意次數,這樣您就可以獲得有意義的樣本集的平均值:

SELECT col1, col2, col3 FROM table WHERE something
GO 1000

還要考慮到,由於這樣的框架隱藏了很多(如果不是大部分)實際的 SQL,因此這可能不是真正的問題;也許它嘗試大規模並行化查詢,或者由於涉及 ORM,它在表上持有硬(獨佔讀寫)鎖。

答案2

從您提供的堆疊追蹤來看,這不是命令超時,而是連線逾時(有這一行:)System.Data.SqlClient.TdsParser.ConsumePreLoginHandshake(...)。這可能是 VS 2010 中的已知錯誤,如果您使用鏡像,請參閱這篇博文了解更多信息

相關內容