ServiceStack OrmLite Command Timeout

When using IDbConnection.ExecuteSql how to set the command timeout?

IDbConnection db = ConnectionFactory.OpenDbConnection(); db.ExecuteSql("..."); 

If I use the IDbCommand.ExecuteSql method (see below), I can set the command timeout, but I get a bunch of warnings about deprecated methods.

 IDbCommand comm = db.CreateCommand() comm.CommandTimeout = 240; comm.ExecuteSql("..."); 
+6
source share
2 answers

With the most recent change, OrmLite no longer provides APIs directly in the IDbCommand object (which were now made internal in the latest version).

But since OrmLite is just the extension methods over ADO.NET that underlie IDbConnection and IDbCommand , you can easily bypass OrmLite extension methods when you need and just use them directly, for example:

 IDbConnection db = ConnectionFactory.OpenDbConnection(); IDbCommand cmd = db.CreateCommand(); cmd.CommandTimeout = 240; cmd.CommandText = "..."; cmd.ExecuteNonQuery(); 

Alternatively, you can set the global CommandTimeout with:

 OrmLiteConfig.CommandTimeout = 240; 
+3
source

A little late for the party, and as you saw in my comment, I had this exact problem. My solution was to extend to the myth proposal and create a new extension method:

 public static partial class IDbConnectionExtensionMethods { public static List<T> Query<T>(this IDbConnection self, string sql, int commandTimeout) { List<T> results = null; self.Exec((dbCmd) => { dbCmd.CommandTimeout = commandTimeout; dbCmd.CommandText = sql; using (var reader = dbCmd.ExecuteReader()) { results = reader.ConvertToList<T>(); } }); return results; } // eo Query<T> } // eo class IDbConnectionExtensionMethods 
+4
source

All Articles