if the time varies a lot for the same client, then you are probably hitting locks, and are using different isolation levels between the two version.
if locks are an issue, switch to row versioning.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am performing a query to the Customers
table with some filters:
var customers = Context.Customers
.AsNoTracking()
.Include(x => x.Client)
.Include(x => x.CreatedByUser)
.Include(x => x.TattleDevices)
.Where(x =>
x.ClientId == clientId
&& x.Status == Status.Active);
Then I want to get the count (for pagination labels):
var totalCount = customers.Count();
And when the query returns a high number (3-4 thousands records), it often times out with this error (from the logs):
EXCEPTION TYPE: Microsoft.Data.SqlClient.SqlException
EXCEPTION MESSAGE: 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): The wait operation timed out.
at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at Microsoft.Data.SqlClient.TdsParser.CheckResetConnection(TdsParserStateObject stateObj) at Microsoft.Data.SqlClient.TdsParserStateObject.WritePacket(Byte flushMode, Boolean canAccumulate) at Microsoft.Data.SqlClient.TdsParserStateObject.ExecuteFlush() at Microsoft.Data.SqlClient.TdsParser.TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc, Boolean sync, TaskCompletionSource
1 completion, Int32 startRpc, Int32 startParam)
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.ExecuteReader(CommandBehavior behavior) at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject) at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable
1.Enumerator.InitializeReader(Enumerator enumerator)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteTState,TResult
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable1.Enumerator.MoveNext() at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable
1 source, Boolean& found)
at lambda_method2338(Closure , QueryContext )
at System.Linq.Queryable.CountTSource
at LiveDispatchApi.Services.Customers.CustomersService.Filter(Int32 clientId, Int32& recordsTotal, Nullable1 takeFrom, Nullable
1 takeCount, String searchValue, Nullable1 orderByIndex, String orderDirection) in R:\NorthStar\live-dispatch-api\LiveDispatchApi\Services\Customers\CustomersService.cs:line 41 at LiveDispatchApi.Controllers.v3._1.CustomersController.Filter(Int32 clientId, SearchRequest request) in R:\NorthStar\live-dispatch-api\LiveDispatchApi\Controllers\v3.1\CustomersController.cs:line 30 ClientConnectionId:68b91fd8-cd84-47b1-b6a6-e358b4df7639 Error Number:-2,State:0,Class:11 STACK TRACE: at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction)
at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at Microsoft.Data.SqlClient.TdsParser.CheckResetConnection(TdsParserStateObject stateObj)
at Microsoft.Data.SqlClient.TdsParserStateObject.WritePacket(Byte flushMode, Boolean canAccumulate)
at Microsoft.Data.SqlClient.TdsParserStateObject.ExecuteFlush()
at Microsoft.Data.SqlClient.TdsParser.TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc, Boolean sync, TaskCompletionSource1 completion, Int32 startRpc, Int32 startParam) 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, TaskCompletionSource
1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method)
at Microsoft.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable1.Enumerator.InitializeReader(Enumerator enumerator) at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func
3 operation, Func3 verifySucceeded) at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable
1.Enumerator.MoveNext()
at System.Linq.Enumerable.TryGetSingleTSource
at lambda_method2338(Closure , QueryContext )
at System.Linq.Queryable.CountTSource
at LiveDispatchApi.Services.Customers.CustomersService.Filter(Int32 clientId, Int32& recordsTotal, Nullable1 takeFrom, Nullable
1 takeCount, String searchValue, Nullable`1 orderByIndex, String orderDirection) in R:\NorthStar\live-dispatch-api\LiveDispatchApi\Services\Customers\CustomersService.cs:line 41
at LiveDispatchApi.Controllers.v3._1.CustomersController.Filter(Int32 clientId, SearchRequest request) in R:\NorthStar\live-dispatch-api\LiveDispatchApi\Controllers\v3.1\CustomersController.cs:line 30INNER EXCEPTION: Microsoft.Data.SqlClient.SqlException Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Void OnError(Microsoft.Data.SqlClient.SqlException, Boolean, System.Action`1[System.Action])
Win32Exception The wait operation timed out.
IMPORTANT:
Any ideas?
I am using EF Core 6.0.9
if the time varies a lot for the same client, then you are probably hitting locks, and are using different isolation levels between the two version.
if locks are an issue, switch to row versioning.