【问题标题】:Entity-Framework SQL command time-out实体框架 SQL 命令超时
【发布时间】:2011-08-14 08:46:56
【问题描述】:

我将Entity Framework 4.0 用作我的DAL 的一部分,用于Web 项目。我有一张繁忙的桌子,经常更新。在更新时,我以Transaction 的身份工作。大部分时间一切正常,但有时我会收到以下错误:

System.Data.EntityCommandExecutionException:发生错误 在执行命令定义时。请参阅内部异常 详情。
---> System.Data.SqlClient.SqlException:超时已过期。
在操作完成之前经过的超时时间或 服务器没有响应。
在 System.Data.SqlClient.SqlConnection.OnError(SqlException 异常,布尔型 breakConnection)
在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
在 System.Data.SqlClient.TdsParser.Run(RunBehavior 运行行为, SqlCommand cmdHandler、SqlDataReader 数据流、 BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
在 System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
在 System.Data.SqlClient.SqlDataReader.get_MetaData()
在 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,字符串 resetOptionsString)
在 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior、RunBehavior runBehavior、布尔 returnStream、布尔 异步)
在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior、runBehavior、布尔返回流、字符串 方法,DbAsyncResult 结果)
在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior、runBehavior、布尔返回流、字符串 方法)
在 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior 行为,字符串方法)
在 System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior 行为)
在 System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand、CommandBehavior 行为)
--- 内部异常堆栈跟踪结束 ---
在 System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand、CommandBehavior 行为)
在 System.Data.EntityClient.EntityCommandDefinition.Execute(EntityCommand entityCommand、CommandBehavior 行为)
在 System.Data.EntityClient.EntityCommand.ExecuteReader(CommandBehavior 行为)
在 System.Data.EntityClient.EntityCommand.ExecuteScalar[T_Result](Func2 resultSelector)
at System.Data.Objects.ObjectContext.ExecuteFunction(String functionName, ObjectParameter[] parameters)
at Downloading.Entities.DownloadingEntities.DoSomethingEx(Nullable
1 id, ...)
在 ...\DAL\DownloadingEntities.Designer.cs:2035 行
在 Downloading.DAL.Repository.DoSomething(Int64 Id, ...)
在 ...\DAL\Repository.cs:982 行

我哪里错了?

【问题讨论】:

  • 告诉我们你在做什么 - 什么代码片段导致了这个错误?你想在那个代码中做什么??
  • @marc_s:我在映射到Stored ProcedureEF 上调用DoSomething。这个SP 更新了我提到的忙表。此表上有约 20,000 条记录,更新频率为每秒约 200-500 条。我在SP 中使用事务和尝试/捕获。

标签: sql-server entity-framework-4 timeout sqlcommand


【解决方案1】:

尝试在 SQL 服务器连接字符串中增加“连接超时”。

MSDN

【讨论】:

  • 这是一个Command Time-Out,它不同于Connection Time-Out
  • 有道理,但实际上我还没有尝试过。你想知道这是EF 的常见情况还是我的设计有问题。
猜你喜欢
  • 2017-09-13
  • 1970-01-01
  • 2012-07-29
  • 1970-01-01
  • 2011-09-08
  • 1970-01-01
  • 2016-11-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多