Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjusting CommandTimeout in Dapper.NET?

I'm trying to run SQL backups through a stored procedure through Dapper (the rest of my app uses Dapper so I'd prefer to keep this portion running through it as well). It works just fine until the CommandTimeout kicks in.

using (var c = SqlConnection(connstring)) {     c.Open();     var p = new DynamicParameters();     // fill out p      c.Execute("xp_backup_database", p, commandType: CommandType.StoredProcedure); } 

The only CommandTimeout setting I know of is in SqlCommand. Is there a way to set this via Dapper?

like image 352
sh-beta Avatar asked Jan 09 '12 20:01

sh-beta


People also ask

How do I set dapper CommandTimeout?

Settings. CommandTimeout = 0; You can initialize this static property on the application load or in the database class constructor. This helps in removing duplication, and in case you decide to change it later, you change it once in one place.

Is CommandTimeout in seconds or milliseconds?

It seems that people are confused as to whether this is seconds or milliseconds. The documentation states that the timeout is in seconds. A 1-minute timeout seems reasonable for most queries.

What is CommandTimeout in connection string?

The time in seconds to wait for the command to execute.

What is CommandTimeout?

The CommandTimeout property sets or returns the number of seconds to wait while attempting to execute a command, before canceling the attempt and generate an error. Default is 30.


1 Answers

Yes, there are multiple versions of the Execute function. One (or more) of them contains the commandTimeout parameters:

public static int Execute(this IDbConnection cnn, string sql,                  dynamic param = null, IDbTransaction transaction = null,                              int? commandTimeout = null, CommandType? commandType = null) 

Taken from SqlMapper.cs

like image 167
jzacharuk Avatar answered Sep 20 '22 14:09

jzacharuk