Adjusting CommandTimeout in Dapper.NET?
There is no need to set command timeout for all queries/Db Calls. You can set it globally like below.
Dapper.SqlMapper.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.
Example from original question with accepted answer added, in case anyone wants it. (Timeout is set to 60 seconds):
using (var c = SqlConnection(connstring))
{
c.Open();
var p = new DynamicParameters();
// fill out p
c.Execute("xp_backup_database", p, commandTimeout: 60,
commandType: CommandType.StoredProcedure);
}
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