.NET Core 2.1 MVC for MySQL数据库中的瞬态故障处理 [英] Transient Failure handling in .net core 2.1 MVC for MySQL Database
问题描述
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:
我的数据库是MySQL 5.7
My DB is MySQL 5.7
我将上面的代码更改为:
I changed the above code to :
这意味着EnableRetryOnFailure对MySQL DB不可用.我现在如何设置重试,延迟等策略?
That means EnableRetryOnFailure is not available for MySQL DB. How do i set the retry, delay etc.. policies now?
如果我尝试设置ExecutionStrategy函数,我也会得到:
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?
推荐答案
有一个用于此的库: https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql
There is a library for this: https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql
设置步骤:
-
从NuGet中下载
Pomelo.EntityFrameworkCore.MySql
.
使用此方法添加到您的班级中:
Add this using to your class:
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
将此添加到您的ConfigureServices
方法:
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);
}
));
这篇关于.NET Core 2.1 MVC for MySQL数据库中的瞬态故障处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!