How to increase command timeout in OrmLite ServiceStack?

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"/> 

and I use the following to run a query that takes 2-3 minutes to return:

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

When you put a breakpoint on the Db object, I see that the connection time is not 666 , but I can’t figure out how to set / increase the command timeout every time I run the above time after 30 seconds, which is the default timeout .

Any ideas?

+4
source share
1 answer

The timeout can be set in OrmLite with OrmLiteConfig.CommandTimeout , since the global configuration can be statically configured once on StartUp:

 OrmLiteConfig.CommandTimeout = 666; 

Or you can instead set CommandTimeout to a specific db connection with:

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

All Articles