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="data source=MySQLServer;initial catalog=My;integrated security=True; ConnectRetryCount=4;ConnectRetryInterval=5; Connection Timeout=5; pooling=False;multipleactiveresultsets=True;App=EntityFramework"" 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
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With