Search code examples
c#entity-framework-coreazure-cosmosdbasp.net-core-2.2graphql.net

Maximum number of retries (6) exceeded while executing database operations with 'CosmosExecutionStrategy'


I am working on API development project using ASP.NET Core 2.2, GraphQL.NET , CosmosDB, Entity Framework Core (Microsoft.EntityFrameworkCore.Cosmos v2.2.4).

While testing the API method which pulls the data from AzureComosDB, sometime I get this error:

Microsoft.EntityFrameworkCore.Storage.RetryLimitExceededException: 'Maximum number of retries (6) exceeded while executing database operations with 'CosmosExecutionStrategy'. See inner exception for the most recent failure.'

I am not sure why this error is popping up intermittently.

Can anyone help me here by providing some guidance to fix this issue?


Solution

  • I would like to know more information about context file as the error says `

    'Maximum number of retries (6) exceeded'

    `. It might cause if you are trying to redeploy database on every request, So Considering you have already deployed database in cosmosdb it is recommended to remove Database.EnsureCreated() as will create performance issues.

    Refer to this documentation for more information https://learn.microsoft.com/en-us/ef/core/providers/cosmos/?tabs=dotnet-core-cli