问题描述
我正在使用ServiceStack OrmLite SqlServer v3.9.71,并具有以下连接字符串:
I am using ServiceStack OrmLite SqlServer v3.9.71 and have the following connection string:
<add key="ConnStr" value="Data Source=my-db;Initial Catalog=Users;Integrated Security=SSPI;Connection Timeout=666"/>
,并且正在使用以下命令运行查询,该查询需要2-3分钟才能返回:
and am using the following to run a query which takes 2-3 minutes to come back:
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 秒,这是默认超时。
When putting a break point on the Db object, I can see the connection time out to be
666
but I can't figure out how to set/increase the Command Timeout every time I run the above it times out after 30
seconds which is the default timeout.
有什么想法吗?
推荐答案
可以使用
OrmLiteConfig.CommandTimeout
在OrmLite中设置超时,作为全局配置可以是或在启动时进行一次配置:
The timeout can be set in OrmLite with
OrmLiteConfig.CommandTimeout
that as a global config can either be statically configured either once on StartUp:
OrmLiteConfig.CommandTimeout = 666;
或者您可以通过以下方式将CommandTimeout设置为特定的数据库连接:
Or you can instead set the CommandTimeout scoped to a specific db connection with:
using (var db = DbFactory.Open())
{
db.SetCommandTimeout(60);
db.Select(...);
}
这篇关于如何增加OrmLite ServiceStack中的命令超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!