2011-08-14 215 views
0

我使用Entity Framework 4.0作爲我的DAL的一部分,用於Web項目。我有一個頻繁更新的繁忙表格。在更新時,我以Transaction的身份完成這項工作。大部分時候一切正常,但有時會出現以下錯誤:Entity-Framework SQL命令超時

System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details.
---> 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.TdsParser.ThrowExceptionAndWarning()
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.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
--- End of inner exception stack trace ---
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.EntityClient.EntityCommandDefinition.Execute(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.EntityClient.EntityCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.EntityClient.EntityCommand.ExecuteScalar[T_Result](Func 2 resultSelector)
at System.Data.Objects.ObjectContext.ExecuteFunction(String functionName, ObjectParameter[] parameters)
at Downloading.Entities.DownloadingEntities.DoSomethingEx(Nullable
1 id, ...)
in ...\DAL\DownloadingEntities.Designer.cs:line 2035
at Downloading.DAL.Repository.DoSomething(Int64 Id, ...)
in ...\DAL\Repository.cs:line 982

我在哪裏錯了?

+0

告訴我們你在做什麼 - 什麼代碼片段導致這個錯誤?你想在那個代碼中做什麼? –

+0

@marc_s:我在映射到「存儲過程」的「EF」上調用了'DoSomething'。這個'SP'更新我提到的繁忙表格。這張表上有大約20,000個記錄,更新頻率是每秒200-500個。我在'SP'中使用事務並嘗試/捕獲。 – Xaqron

回答

0

嘗試在您的SQL服務器連接字符串中增加「連接超時」。

MSDN

+2

這是一個'Command Time-Out',它與'Connection Time-Out'不同' – Xaqron

+0

並且設置ObjectContext.CommandTimeout? – elevener

+0

這很有道理,但實際上我還沒有嘗試過。你想知道這是否是'EF'的常見情況,或者我的設計有問題。 – Xaqron