代码之家  ›  专栏  ›  技术社区  ›  MaYaN

如何增加OrmLite ServiceStack中的命令超时?

  •  5
  • MaYaN  · 技术社区  · 10 年前

    我正在使用ServiceStack OrmLite SqlServer v3.9.71,并具有以下连接字符串:

    <add key="ConnStr" value="Data Source=my-db;Initial Catalog=Users;Integrated Security=SSPI;Connection Timeout=666"/>
    

    我使用以下命令运行一个需要2-3分钟才能返回的查询:

    using (Db)
    {
        var result = new ResultDto();
    
        Parallel.Invoke(
           () => { result.StatOne = Db.Dictionary<DateTime, int>(query1); },
           () => { result.StatTwo = Db.Dictionary<DateTime, int>(query2); }
        );
    
        return result;
    }
    

    在Db对象上放置断点时,我可以看到连接超时 666 但我无法确定每次运行以上命令时,如何设置/增加命令超时 30 秒,这是默认超时。

    有什么想法吗?

    1 回复  |  直到 10 年前
        1
  •  16
  •   mythz    10 年前

    可以在OrmLite中使用 OrmLiteConfig.CommandTimeout 作为全局配置 statically configured 启动时:

    OrmLiteConfig.CommandTimeout = 666;
    

    或者,您可以改为使用以下命令将CommandTimeout范围设置为特定的数据库连接:

    using (var db = DbFactory.Open())
    {
        db.SetCommandTimeout(60);
        db.Select(...);
    }