Entity Framework Core Interview Question #145
What is database command timeout in EF Core?
Performance, Raw SQL, Stored Procedures & Advanced Queries Senior Advanced
Quick Interview Answer
A command timeout limits how long EF Core waits for a database command before the provider treats it as timed out. Raising the timeout can be appropriate for known long-running administrative or reporting operations, but it should not hide inefficient queries, blocking, or missing indexes. Investigate the reason for slowness first.
Detailed Explanation
A command timeout limits how long EF Core waits for a database command before the provider treats it as timed out. Raising the timeout can be appropriate for known long-running administrative or reporting operations, but it should not hide inefficient queries, blocking, or missing indexes. Investigate the reason for slowness first.
Code Example
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(connectionString,
sql => sql.CommandTimeout(30)));