调整的CommandTimeout在Dapper.NET?CommandTimeout、Dapper、NET

2023-09-04 06:59:03 作者:潮汐怎遇潮落

我想通过存储过程通过小巧玲珑的运行SQL备份(我的应用程序的其余部分使用小巧精致,所以我倒是preFER继续通过它这一部分运行以及)。它工作得很好,直到将CommandTimeout踢

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);
}

唯一的CommandTimeout设置我知道是的SqlCommand。有没有办法通过小巧玲珑的设置吗?

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

推荐答案

是的,有多个版本的执行功能。其中的一个(或更多)包含将CommandTimeout参数:

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)

从SqlMapper.cs