You receive the following error when attempting to establish a secure SSL connection using a connection string to an SQL Database Server: "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."
Since we use a self-signed certificate please disable SSL verification, you need to modify your connection string by adding TrustServerCertificate=True. This parameter instructs your connection to trust the server's SSL certificate.
For example:
Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;Encrypt=True;TrustServerCertificate=True;
When is TrustServerCertificate=True safe? It is safe whenever your app and SQL Server run on the same host or a trusted private network — the connection never crosses a network an attacker could sit on. For the full breakdown of when to trust the certificate versus install a proper one, read our guide: Fix the ASP.NET Core SQL Server certificate-not-trusted error. Every ASP.NET hosting plan includes a real SQL Server 2022 instance on the same server as your app, so the local connection is both safe and works out of the box.