Base solution for your next web application
Open Closed

How to add Connect Timeout for EF Core? #3329


User avatar
0
trendline created

In my application, there will be large data be queried, sometimes it will timeout to connect database, where I can set timeout for EF core?

I tried add below property in EF Core constructor but it seems it doesn't work, and when using EF migration update database, it will failed because this change.

public MyDbContext(DbContextOptions<MyDbContext> options)
            : base(options)
        {
            this.Database.SetCommandTimeout(180);
        }

Can I set it in connection string? Hope you can give me some guides.

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Can you try this in PrInitialize method of your module ?

    Configuration.UnitOfWork.Timeout = TimeSpan.FromMinutes(3);
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    trendline created

    Add this in application module or core module?

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    trendline created

    It seems it doesn't work, it still execute the sql with default timeout 30 seconds.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Have you tried it in your web module ?

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)