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

12.6k Views Asked by At

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?

3

There are 3 best solutions below

0
On BEST ANSWER

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

0
On

First of all, have you checked the inner exception as stated in the 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.'

it might give a clue as to why it is failing.

Now, this error is caused by the cosmos retry stategy. If an operation failes it will retry it to up to six times.

You can modify this strategy but the default can be found here. The fact that it is retried indicates it it an error that might be gone when retried. A good example is a glitch in the netwerk connection (like, when the wifi signal is bad). Another one could be the fact that the requests are exceeding the provisioned Request Unit limits.

0
On

You can solve like this,

Open IIS then"Applications Pools", You should right click that you have choosed application pool. Then choose "Advanced Settings". Click three point on the Identity tab then you should choose "LocalSystem" from field of "Built-in-account" If you do this way, you don't need to create a user in database.

enter image description here