I noticed that using the asynchronous API in Dapper.NET the command timeout value I pass in the extension method is not respected. Then I came across the MSDN documentation of the SqlCommand.CommandTimeout and it seems that this is something it is not "supported".
The CommandTimeout property will be ignored during asynchronous method calls such as BeginExecuteReader.
I'm using the following methods in a base class.
public async Task<int> ExecuteAsync(string sql, object param = null,
CommandType commandType = CommandType.Text, int? commandTimeout = null, IDbTransaction transaction = null)
{
using (var connection = Connection)
{
Task<int> queryTask = connection.ExecuteAsync(sql, param, transaction, commandTimeout ?? CommandTimeoutDefault, commandType);
int result = await queryTask.ConfigureAwait(false);
connection.Close();
connection.Dispose();
return result;
}
}
public async Task<IEnumerable<TEntity>> QueryAsync(string sql, object param = null,
CommandType commandType = CommandType.Text, int? commandTimeout = null, IDbTransaction transaction = null)
{
using (var connection = Connection)
{
Task<IEnumerable<TEntity>> queryTask = connection.QueryAsync<TEntity>(sql, param, transaction, commandTimeout ?? CommandTimeoutDefault, commandType);
IEnumerable<TEntity> data = await queryTask.ConfigureAwait(false);
connection.Close();
connection.Dispose();
return data;
}
}
Say CommandTimeoutDefault
is 30, I can se that a request taking 50 seconds will still be evaluated.
Any thoughts how to disconnect and dispose the connection in a timeout interval using asynchronous Dapper.NET API?
using
– Marc Gravell♦ Dec 25 '17 at 9:57