简体   繁体   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

I am using the following linq query using EF core.我正在使用以下使用 EF 核心的 linq 查询。 and getting the following error:并收到以下错误:

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

Not sure what am i doing wrong here.不知道我在这里做错了什么。

ECUserId is varchar column and there is no index set on this table for this column. ECUserId 是 varchar 列,并且此表上没有为此列设置索引。 Also checked the collation and it is set to 'SQL_Latin1_General_CP1_CI_AS' which is case sensitive.还检查了排序规则并将其设置为区分大小写的“SQL_Latin1_General_CP1_CI_AS”。

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

The userStandby table has got around 126580 records. userStandby 表有大约 126580 条记录。

Can anyone help me how to fix the above timeout error?谁能帮我解决上述超时错误?

Created an index on this column but still getting the same timeout error:在此列上创建了一个索引,但仍然出现相同的超时错误:

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

The linq query is not generating the sql query with where condition. linq 查询未生成带有 where 条件的 sql 查询。 What am i doing wron here please?请问我在这里做错了什么?

thanks谢谢

You can set a longer timeout when setting up your DbContext:您可以在设置 DbContext 时设置更长的超时时间:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL Server异常:超时已过期。 操作完成之前经过的超时时间或服务器未响应 - SQL Server Exception:Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding ExecuteQueryin linq:超时已过期。 操作完成之前经过的超时时间或服务器没有响应 - ExecuteQueryin linq :Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding Linq Count() 超时 - 执行超时已过期。 操作完成前超时时间已过或服务器未响应 - Linq Count() timing out -Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding 超时已过。 在操作完成之前超时时间已过或服务器没有响应。 该语句已终止 - Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated 超时时间已到。 操作完成之前经过的超时时间或服务器未响应 - Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding 超时时间已到。 操作完成之前经过的超时时间或服务器未响应 - Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding 在sis中执行软件包会导致超时过期。 操作完成之前经过的超时时间或服务器未响应 - Execute package in ssis causes Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding 超时时间已到。 在操作完成之前超时或服务器没有响应。 在远程Windows .net上工作 - Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. working on remote windows .net 超时已过。 操作完成前超时时间已过或服务器未响应 - Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding '执行超时已过期。 在操作完成之前超时时间已过或服务器没有响应。 - 'Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM