Timeout exception for deleting record with primary key

485 views Asked by At

I use EF Core 6.0 and EntityFramework.Plus.EFCore 6.14.

I use the following method to delete a record from a table:

public void DeleteDocument(int id) 
{
    using var ctx = this.CreateContext();
    ctx.ArticleDocuments.Where(x => x.Id == id).Delete();
}

When I execute the delete, I get the following exception:

Microsoft.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

System.ComponentModel.Win32Exception (258): Der Wartevorgang wurde abgebrochen.

at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)
at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at Microsoft.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at Microsoft.Data.SqlClient.SqlDataReader.get_MetaData()
at Microsoft.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean isAsync, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method) at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at Microsoft.Data.SqlClient.SqlCommand.ExecuteScalar() at Z.EntityFramework.Extensions.BatchDelete.<>c.?(DbCommand ?) at Z.EntityFramework.Extensions.BatchDelete.Execute[T](IQueryable1 query)
at Z.EntityFramework.Plus.BatchDeleteExtensions.Delete[T](IQueryable1 query, Action1 batchDeleteBuilder)
at Z.EntityFramework.Plus.BatchDeleteExtensions.Delete[T](IQueryable`1 query)
at E3kWebshopInterface.Data.Repositories.ArticleDocumentRepository.DeleteDocument(Int32 id) in D:\DATEN\Projekte\M-TECH\E3kWebshop\E3kWebshopInterface\E3kWebshopInterface\Data\Repositories\ArticleDocumentRepository.cs:line 77
at E3kWebshopInterface.Controllers.ArticleDocumentController.RunDocuments(ArticleIdx idx) in D:\DATEN\Projekte\M-TECH\E3kWebshop\E3kWebshopInterface\E3kWebshopInterface\Controllers\ArticleDocumentController.cs:line 93

ClientConnectionId:75232be6-9dfa-4c4c-8b5f-ff7bf471a3fa
Error Number:-2,State:0,Class:11

This is my mapping:

public abstract class BaseEntity 
{
    public DateTime CreatedOn { get; set; }
    public DateTime UpdatedOn { get; set; }
}

public class ArticleDocument : BaseEntity 
{
    public int Id { get; set; }
    [Required]
    public int ClientId { get; set; }
    [Required]
    public string E3kArticleKey { get; set; }
    [Required]
    public string PepperArticleKey { get; set; }
    [Required]
    public string DocumentName { get; set; }
    [Required]
    public string DocumentHash { get; set; }
    [Required]
    public bool IsImage { get; set; }
}

The database is on SQL Server 2019. The table ArticleDocument contains 800 rows and Id is the primary key. My application is the one and only which uses the database and there is only one instance running.

I can't explain why a timeout can occur here.

Edited at 29.August 2022

This is the Query-Plan: https://www.brentozar.com/pastetheplan/?id=S1wC0Scko

0

There are 0 answers