Wednesday, April 29, 2020

How to set command timeout in asp.net core in entity framework

If you're using the DI container to manage the DbContext (i.e. you're adding the DbContext to the service collection), the command timeout can be specified in the options.
In Startup.cs  file ConfigureServices method.
services.AddDbContext<YourDbContext>(options => options.UseSqlServer(
    this.Configuration.GetConnectionString("YourConnectionString"),
    sqlServerOptions => sqlServerOptions.CommandTimeout(60))
);
 Same code are as below
public void ConfigureServices(IServiceCollection services)
        {
          services.AddDbContext<KLASSAKTContext>(option => option.UseSqlServer(Configuration.GetConnectionString("DbKlassakt"),
                sqlServerOptions => sqlServerOptions.CommandTimeout(60)));
}
Hope it is help you,
Arjun Walmiki


No comments:

Post a Comment