services.AddDbContext<MyContext>(options =>
{
options.UseSqlServer(mysqlConnection,
sqlServerOptionsAction: sqlOptions =>
{
sqlOptions.EnableRetryOnFailure(
maxRetryCount: 10,
maxRetryDelay: TimeSpan.FromSeconds(30),
errorNumbersToAdd: null);
});
});
I found this code snippet at:
My DB is MySQL 5.7
I changed the above code to :
That means EnableRetryOnFailure is not available for MySQL DB. How do i set the retry, delay etc.. policies now?
Also if i try to set the ExecutionStrategy function i get this:
Then i tried Create my own Strategy using:
public class MyStrategy: ExecutionStrategy
{
......
}
but how to use this class now?
There is a library for this: https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql
Setup steps:
Donwload Pomelo.EntityFrameworkCore.MySql
from NuGet.
Add this using to your class:
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
Add this to your ConfigureServices
method:
services.AddDbContextPool<ApplicationDbContext>(
options => options.UseMySql("Server=localhost;Database=ef;User=root;Password=123456;",
mySqlOptions =>
{
mySqlOptions.ServerVersion(new Version(5, 7, 17), ServerType.MySql)
.EnableRetryOnFailure(
maxRetryCount: 10,
maxRetryDelay: TimeSpan.FromSeconds(30),
errorNumbersToAdd: null);
}
));