在 Dapper C# 中使用存储过程时处理超时

问题描述 投票:0回答:0

我有一个系统,按需执行存储过程,当查询停止执行并抛出异常时,它应该有一定的超时时间。

var command = new CommandDefinition(commandText: procedure.SqlName,
    commandTimeout: _options.RequestTimeout,
    parameters: parameters,
    commandType: CommandType.StoredProcedure,
    flags: CommandFlags.Buffered);

var result = await connection.ExecuteReaderAsync(command);

当我尝试像上面那样在 Dapper 中使用 CommandDefinition 对象指定执行超时时,查询将忽略它并在需要时运行它。但是,当我使用原始 SQL 而不是存储过程时,超时似乎应该触发。

当我通过 Dapper 执行存储过程时,是否有可能出现执行超时?

c# timeout dapper
© www.soinside.com 2019 - 2024. All rights reserved.