0

**Microsoft.Data.SqlClient.SqlException **(0x80131904): 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.) System.ComponentModel.Win32Exception (0x80090325): The certificate chain was issued by an authority that is not trusted. at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)

using WebApplication2.Data;
using WebApplication2.Model.Domain;


namespace WebApplication2.Repositories
{
    public class RegionRepository : IRegionRepository
    {
        private readonly WalksDbContext walksDbContext;
        public RegionRepository(WalksDbContext walksDbContext)
        {
            this.walksDbContext = walksDbContext;
        }
        public IEnumerable<Region> GetAll()
        {
            return walksDbContext.Regions.ToList();
        }
    }
}

  • Do these links answer your question? ["The certificate chain was issued by an authority that is not trusted" when connecting DB in VM Role](https://stackoverflow.com/q/17615260/113116), ['The certificate chain was issued by an authority that is not trusted in Microsoft.Data.SqlClient' in working project](https://stackoverflow.com/q/70112568/113116) – Helen Nov 14 '22 at 10:03
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Nov 14 '22 at 10:15
  • Hi @Helen, this is not answer related to my topic. – Sanjeev singh kushvaha Nov 14 '22 at 11:00
  • Are you sure your issue is not the same? The error message implies that your backend SQL server uses a self-signed SSL certificate. The linked Q&As suggest either installing a proper cert from a trusted CA, or changing the connection string to trust your custom cert. – Helen Nov 14 '22 at 11:32
  • @Helen I will check once again then I'll tell you. – Sanjeev singh kushvaha Nov 15 '22 at 10:32
  • Hi @Helen, for this error I used local database so SSL provide error is resolved. my local database name is **(localdb)\MSSQLLocalDB** and also change in **appsetting.json** like this '{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "AllowedHosts": "*", "ConnectionStrings": { "NzWalks": "server=(localdb)\\MSSQLLocalDB;database=NzWalksDb;trusted_connection=true" } }' – Sanjeev singh kushvaha Nov 16 '22 at 09:04

2 Answers2

0

I used local database so SSL provide error is resolved. my local database name is (localdb)\MSSQLLocalDB and also change in appsetting.json like this

    { 
     "Logging": {
         "LogLevel": { 
            "Default": "Information",
            "Microsoft.AspNetCore": "Warning"
      }
 },
 "AllowedHosts": "*",
 "ConnectionStrings": {
    "NzWalks": "server=
 (localdb)\\MSSQLLocalDB;database=NzWalksDb;trusted_connection=true"
 }
}
0

Microsoft.Data.SqlClient 4.0 is uses ENCRYPT=True by default.

Either you put a certificate on the server (not a self signed one) or you add

TrustServerCertificate=Yes;

to the connection string.

Emond
  • 50,210
  • 11
  • 84
  • 115