簡體   English   中英

C# entityframework 核心拋出 Timeout expired。 操作完成前超時時間已過或服務器無響應

[英]C# entityframework core throwing Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding

我正在使用以下使用 EF 核心的 linq 查詢。 並收到以下錯誤:

Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

不知道我在這里做錯了什么。

ECUserId 是 varchar 列,並且此表上沒有為此列設置索引。 還檢查了排序規則並將其設置為區分大小寫的“SQL_Latin1_General_CP1_CI_AS”。

string ECUserId = "TN504060"
var userStandby = await _context.UserStandby
                                .Where(standBy => ECUserId.Equals(standBy.ECUserId, 
                                       StringComparison.OrdinalIgnoreCase))
                                .FirstOrDefaultAsync();

userStandby 表有大約 126580 條記錄。

誰能幫我解決上述超時錯誤?

在此列上創建了一個索引,但仍然出現相同的超時錯誤:

GO
CREATE NONCLUSTERED INDEX [IX_UserStandby_ECUserId]
    ON [dbo].[UserStandby]([ECUserId] ASC);

linq 查詢未生成帶有 where 條件的 sql 查詢。 請問我在這里做錯了什么?

謝謝

您可以在設置 DbContext 時設置更長的超時時間:

        services.AddDbContext<MyDbContext>(config =>
          config.UseSqlServer(
             "MyConnectionString",
             providerOptions =>
             {
                 providerOptions.CommandTimeout(180); <-- Timeout in seconds
             })
        );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM