0

我需要连接一个使用实体框架核心 6 在线托管的 mariaDB 数据库。

这是我的连接字符串:

  "ConnectionStrings": {
    "DBConnection": "Server=148.163.126.69;Port=3306;Database=dbname;Uid=db_admin;Pwd=pass;connect timeout=100;default command timeout=200;"
  },

program.cs 的第一部分:

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<UsersContext>(options =>
{
    options.UseMySql(builder.Configuration.GetConnectionString("DBConnection"),
     ServerVersion.AutoDetect(builder.Configuration.GetConnectionString("DBConnection")),
    builder =>
    {
        builder.EnableRetryOnFailure(5, TimeSpan.FromSeconds(10), null);
    });
});

但我不断收到此错误:

Unable to connect to any of the specified MySQL hosts.

我已经尝试与本地 SQLServer 连接,它工作正常。

4

0 回答 0