【问题标题】:EntityCommandExecutionException:Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not respondingEntityCommandExecutionException:超时已过期。操作完成前超时时间已过或服务器无响应
【发布时间】:2014-12-16 14:31:54
【问题描述】:

我有一个 EntityFramework 选择语句,它返回大约 50K 行。对于这个简单的选择命令,我得到了这个例外

var db = new DBEntity();
db.CommandTimeout = 350; 
var actCosts = (from i in db.Products
                            where i.productID== productID
                            select i).ToList();

数据库位于 Azure 中。我已通过 SSMS 连接以了解检索行所需的实际时间,它需要 4:30 分钟才能带来所有数据。所以我将 Commandtimeout 设置为 350 秒。但是没用

上面和这个有什么性能差异

var actCosts = db.Products.Where(t => t.productID== productID).ToList();

【问题讨论】:

  • 您是否尝试设置更大的超时时间? SMSS 使用其他方法来检索数据,并且可能为此进行了优化。首先尝试运行一个.FirstOrDefault(),看看它是否及时返回数据。
  • 你在哪里设置超时时间?
  • var db = new DBEntity();db.CommandTimeout = 350;
  • 使用您设置超时的代码编辑您的答案。 tnx
  • 另外,您在 SSMS 中用于选择数据的查询也会很有用。也许那里有一些问题。

标签: sql azure entity-framework-5


【解决方案1】:

首先尝试运行一个.FirstOrDefault(),看看它是否及时返回数据

var actCosts = (from i in db.Products
                            where i.productID== productID
                            select i).FirstOrDefault();

如果可行,我建议设置更大的 Timeout,例如 1000,然后查看是否返回结果。

我相信 SSMS 使用其他方法来检索数据,并且可能比简单的 .ToList() 方法对此进行了更好的优化。

【讨论】:

    猜你喜欢
    • 2012-07-24
    相关资源
    最近更新 更多