Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core Web API - update-database failed due to provider: SSL Provider, error: 0

In my ASP.NET Core-6 Web API using Entity Framework, I have this code:

I am using IdentityDbContext.

ApplicationDbContext:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
    {
    }
    public DbSet<ApplicationUser> ApplicationUsers { get; set; }
    public DbSet<ApplicationRole> ApplicationRoles { get; set; }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        builder.ApplyConfigurationsFromAssembly(typeof(ApplicationDbContext).Assembly);
        base.OnModelCreating(builder);
    }
}

ConnectionConfiguration:

public static class ConnectionConfiguration
{
    public static void AddDbContextAndConfigurations(this IServiceCollection services, IWebHostEnvironment env, IConfiguration config)
    {
        services.AddDbContextPool<ApplicationDbContext>(options =>
        {
            string connStr;
            connStr = config.GetConnectionString("MssqlDbConnection");
            options.UseSqlServer(connStr);
        });
    }
}

Program.cs:

var builder = WebApplication.CreateBuilder(args);
ConfigurationManager configuration = builder.Configuration;
var environment = builder.Environment;

builder.Services.AddDbContextAndConfigurations(environment, configuration);

Then the connectionString in the appsettings.json:

"ConnectionStrings": { "MssqlDbConnection": "Server=131.21.22.110,62431;Database=MyDb;User Id=sksswm; Password=asdffgg;" },

When I ran the add-migration, it was successful. But when I did

update-database, I got this error:

A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)

I changed

"MssqlDbConnection": "Server=131.21.22.110,62431;Database=MyDb;User Id=sksswm; Password=asdffgg;"

to

"MssqlDbConnection": "Server=131.21.22.110,62431;Database=MyDb;User Id=sksswm; Password=asdffgg; Trusted_Connection=True;"

But the error still not resolved.

I can even manually (successfully) login to the MSSQL DB using the same credential.

How do I correct this?

Thanks

like image 986
Ayobamilaye Avatar asked Dec 18 '25 02:12

Ayobamilaye


1 Answers

I added trustServerCertificate=true to the connectionString and got it resolved.

like image 126
Ayobamilaye Avatar answered Dec 20 '25 15:12

Ayobamilaye



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!