简体   繁体   中英

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. 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. Also checked the collation and it is set to 'SQL_Latin1_General_CP1_CI_AS' which is case sensitive.

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.

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. What am i doing wron here please?

thanks

You can set a longer timeout when setting up your DbContext:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question SQL Server Exception:Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding ExecuteQueryin linq :Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding 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 Execute package in ssis causes 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. 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