Dapper Integration: GetDbConnectionAsync() doesn't respect CommandTimeout Settings from DbContext
Is there an existing issue for this?
- [X] I have searched the existing issues
Description
On my Dapper Repository the method GetDbConnectionAsync() always uses the default command timeout = 30 seconds.
In my factory I setup the DbContext like that:
var builder = new DbContextOptionsBuilder<SimonDbContext>()
.UseSqlServer(configuration.GetConnectionString("Default"),
options => {
options.CommandTimeout((int)TimeSpan.FromMinutes(10).TotalSeconds);
options.EnableRetryOnFailure();
});
I even tried it on DbContext constructor:
public SimonDbContext(DbContextOptions<SimonDbContext> options)
: base(options)
{
Database.SetCommandTimeout((int)TimeSpan.FromMinutes(10).TotalSeconds);
}
I need a higher command timeout in some cases. Since
var dbConnection = await GetDbConnectionAsync();
returns an established connection the command timeout is writeprotected.
I'm not sure if this is a bug but I can't figure it out a solution myself.
Thanks for your help! Alex
Reproduction Steps
- Set a higher command timeout on dbcontext creation
- check the command timeout on a Dapper connection created with GetDbConnectionAsync
Expected behavior
The command timeout from dbcontext should be used.
Actual behavior
The default command timeout of 30 seconds is used.
Version
7.4
hi
https://github.com/dotnet/efcore/issues/6246
I just found out that you can add the command timeout as parameter to the command method:
return (await dbConnection.QueryAsync<ExportListDto>( sql, transaction: await GetDbTransactionAsync(), commandTimeout: 300, param: parameters ) ).ToList();
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.