0

Long story short I have a problem establishing connection between my Web API .NET application and my SQL Server database, which I use Windows authentication for.

Once I make a request through my API controller in the application, I get back an exception

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.

I have seen all threads where people gave advice about setting Encrypt to false and TrustServerCertificate to true in the connection string but neither of those worked for me.

My current appsettings.json file looks like this:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",

  "ConnectionStrings": {
    "DefaultConnection": "Server=LAPTOP-0VDNO79B\\SQLEXPRESS;Database=cv_database;Encrypt=False;TrustServerCertificate=True;"
  }
}

Any advice is greatly appreciated.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
KChimev
  • 11
  • 1
  • 2
    Does this answer your question? ["The certificate chain was issued by an authority that is not trusted" when connecting DB in VM Role from Azure website](https://stackoverflow.com/questions/17615260/the-certificate-chain-was-issued-by-an-authority-that-is-not-trusted-when-conn) Or I guess the answers are the ones you're referring to. Do you have multiple appsettings.json files? – Jeppe Apr 27 '23 at 18:53
  • Have you tried actually using a proper certificate for SQL Server, rather than the builtin self-signed one? – Charlieface Apr 27 '23 at 18:59
  • Are you using `Microsoft.Data.SqlClient` version 5 or later? The `Encrypt` options changed from bool values `False/True` to a new enumeration `Optional/Mandatory/Strict`. – AlwaysLearning Apr 27 '23 at 21:15

0 Answers0