Search code examples
sql-serverconnectioncertificate

How to fix SQL Server 2019 connection error due to certificate issue


I am using a .NET console app to test SQL Server 2019 database connection and get following error message:

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.)

The user id and password are valid. The C# code is not using any encryption. I have not configured any certificate in SQL Server configuration.

  1. Is certificate required in SQL Server 2019?
  2. Can I get a self generated cert from the SQL Server?
  3. If no self-generated cert available, where can I get a valid certificate for free?

Solution

  • For me this did the trick

    • In Visual Studio, open the Server Explorer pane.
    • Right-click on the data connection (database) and select "Modify connection".
    • Check the box for "Trust Server Certificate".

    Modify connection - trust server certificate

    Note: this may not be advisable in a production environment, but I was just testing a local non-prod app so it solved the problem for me.