Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do ConnectRetryInterval and ConnectRetryCount Entity Framework SQL connection string settings interfer with Execution strategy?

I wonder if ConnectRetryInterval and ConnectRetryCount Entity Framework SQL connection string settings make EF to retry DB failed updates. Please, see example of the EF connection string with the settings below

 <add key="MyConnectionString" value ="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=MySQLServer;initial catalog=My;integrated security=True;    ConnectRetryCount=4;ConnectRetryInterval=5; Connection Timeout=5; pooling=False;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Another question is about ConnectRetryInterval&ConnectRetryCount interference with DbExecutionStrategy/SqlAzureExecutionStrategy retry logic. Do connection settings retry first and Execution Strategy after that? Or, connection settings and Execution Strategy overlap each other's retry attempts depending on retry time intervals?

Thanks

like image 878
MBK Avatar asked Jan 17 '18 22:01

MBK


People also ask

Which of the following connection retry execution strategies does not retry at all by default?

DefaultSqlExecutionStrategy: this is an internal execution strategy that is used by default. This strategy does not retry at all, however, it will wrap any exceptions that could be transient to inform users that they might want to enable connection resiliency.

How should transient network connectivity issues in Azure SQL be handled by a client application?

Applications that connect to your database should be built to expect these transient errors. To handle them, implement retry logic in their code instead of surfacing them to users as application errors. If your client program uses ADO.NET, your program is told about the transient error by the throw of SqlException.

What should be the connection string for SQL Server?

Server=myServerName,myPortNumber;Database=myDataBase;User Id=myUsername;Password=myPassword; The default SQL Server port is 1433 and there is no need to specify that in the connection string.

What is execution strategy Entity Framework?

The execution strategy works by rolling back the whole transaction if a transient failure occurs, and then replaying each operation in the transaction again; each query and each call to SaveChanges will be retried as a unit.


1 Answers

I'm relying on this Microsoft white paper that covers "Idle Connection Resiliency" as the reference to answer your question. (Note that the white paper is in a downloaded MS Word/.docx article format.)

ConnectRetryCount and ConnectRetryInterval settings are associated with the MS SQL Server (v14+) drivers, independent of Entity Framework. Thus, as long both the server and the driver support it and the settings have been enabled in the connection string, they're expected to work within EF as well. However, in your example, Pooling is set to false. This will explicitly prevent pooling and open a new connection every time, so there will be no "idle" connection to work with.

EF Core's use of ExecutionStrategy is different since it can handle transaction errors and allow you to implement custom tactics depending on the type of error. You can also simply call EnableRetryOnFailure() to use the default ExecutionStrategy when configuring SQL provider options. There is no overlap between the SQL driver's idle connection retries and EF's transaction failure retries.

like image 117
Cahit Avatar answered Sep 23 '22 05:09

Cahit