0

I need to connect with a mariaDB database which is hosted online with entity framework core 6.

here my connection string:

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

first part of 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);
    });
});

But I keep getting this error:

Unable to connect to any of the specified MySQL hosts.

I already tried to connect with a local SQLServer and it works fine.

Gabriel Luci
  • 38,328
  • 4
  • 55
  • 84
Mahdi Benaoun
  • 67
  • 1
  • 8

0 Answers0