I am finding that neither the DatabaseFacade.SetCommandTimeout
method nor the SqlServerDbContextOptionsBuilder.CommandTimeout
method are having any effect on my code and instead a long running SQL command just continues indefinitely.
My context object looks something like this:
public class MyDataContext : DbContext
{
public MyDataContext()
{
base.Database.SetCommandTimeout(60);
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
...
optionsBuilder.UseSqlServer(connection, sqlServerOptions => sqlServerOptions.CommandTimeout(60));
}
}
But then when I execute the code in my web API:
using var dbContext = new MyDataContext();
var timeout = dbContext.Database.GetCommandTimeout(); // this, as expected, returns "60"
var listOfEntities = dbContext.MyLargeSetOfEntities.ToList(); // this, however, just runs way longer than a minute (it is returning an immense amount of data to test the timeout)
Is there somewhere that could be overriding this value and making it indefinite?