【问题标题】:Timeout issue using codefirststoredprocs in MVC5/EF 6. Error reading from stored proc dbo.[...]: Timeout expired在 MVC5/EF 6 中使用 codefirststoredprocs 时出现超时问题。从存储的 proc dbo 读取时出错。[...]:超时已过期
【发布时间】:2013-11-13 03:24:12
【问题描述】:

为了一次处理近 70K 条记录,我在我的应用程序中使用了 codefriststoredprocs 2.5.0。由于记录很少,一切正常,但有大量数据,我收到“等待操作超时”异常。 我尝试通过以下方式将默认命令超时值从 30 秒修改为 600 秒。

//Previous approach
   ((System.Data.Entity.Infrastructure.IObjectContextAdapter)this.db).ObjectContext.CommandTimeout = 600;

//New approach for EF 6
this.db.Database.CommandTimeout = 600;

但仍会在 30 秒后收到连接超时消息。我还将 web.config 设置连接超时值修改为 600 秒(我知道这与命令超时值不同,但试一试)。 我觉得问题出在 codefirststoredprocs 库上,它在执行存储过程时将命令超时值更改为默认值。有什么方法可以解决这个问题,或者我应该使用其他方法在我的应用程序中使用存储过程。

提前致谢。

【问题讨论】:

    标签: asp.net-mvc entity-framework timeout cfstoredproc


    【解决方案1】:

    首先,我要感谢CodeFirstStoredProcs 团队为解决此问题所做的努力和协作。

    我猜,如前所述,CodeFirstStoredProcs 库中的命令超时值可能已默认为 30 秒。

    在他们的新版本(2.6 版)中,他们在CallStoredProc<> 方法中添加了“命令超时”参数,这有助于我为命令超时设置默认值 终于解决了我的问题。

    为了在我的案例中处理近 70K 条记录,我将 CommandTimeout = 0 设置为 CallStoredProc<> 方法。这增加了执行存储的无限等待时间 过程。

    再次感谢CodeFirstStoredProcs 团队。 :)

    【讨论】:

    • 构造函数是new StoredProc<Model>() { commandTimeout = 0 }
    【解决方案2】:

    我在换到 EF6 时遇到了同样的问题。

    您可能将 CommandTimeout 设置在错误的位置。尝试在创建上下文的位置设置 CommandTimeout,如下所示:

    var context = new Entities();
    context.CommandTimeout = 600;
    

    还要检查在创建上下文后是否使用您的方法更改了 CommandTimeout。如果是这样,那么可能还有其他问题。

    【讨论】:

      猜你喜欢
      • 2016-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-23
      • 1970-01-01
      • 2023-02-22
      • 2015-11-06
      相关资源
      最近更新 更多