Hi @blom buffin
Thank you for reaching out to the Microsoft Q&A forum!
The error "The certificate chain was issued by an authority that is not trusted" typically occurs when the client machine doesn't trust the self-signed certificate used by SQL Server. By default, SQL Server 2019 uses a self-signed certificate if no trusted Certificate Authority (CA) certificate is installed.
When connecting with encryption enabled and TrustServerCertificate set to False, the .NET 8 SQL client attempts to validate the certificate chain. Since the self-signed certificate isn't issued by a recognized CA, validation fails and the connection is refused. This is expected behavior in newer client drivers to enforce stricter security.
That said, from my perspective view, in order to resolve and mitigate this issue, you can follow the instruction below:
Option 1: Use TrustServerCertificate=True in the connection string
This option bypasses validation and trusts the certificate as-is, avoiding the error.
string connectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;Encrypt=True;TrustServerCertificate=True;"
Note: This reduces security, as it could expose you to man-in-the-middle attacks in untrusted environments. Avoid in production.
Option 2: Use a certificate signed by a trusted CA
Get a certificate from a trusted CA and install it on the SQL Server. This will avoid trust chain issues.
Option 3 (optional): Install the self-signed certificate's root in Trusted Root Certification Authorities store on the client machine.
**Step 1: Export the Certificate from SQL Server **
- On the SQL Server machine (where SQL Server 2019 is installed), open Microsoft Management Console (MMC) by pressing Win+R, typing mmc, and hitting Enter.
- In MMC, go to File > Add/Remove Snap-in.
- Select Certificates > Add > Computer account > Local computer > Finish > OK.
- Expand Certificates (Local Computer) > Personal > Certificates.
- Find the self-signed cert used for SQL Server encryption (it should match the one configured in SQL Server Configuration Manager under SQL Server Network Configuration > Protocols for [Instance] > Properties > Certificate tab).
- Right-click the cert > All Tasks > Export.
- In the wizard: Next > No, do not export the private key > Next > DER encoded binary X.509 (.CER) > Next > Choose a file name/location (e.g., sqlservercert.cer) > Next > Finish.
- Transfer this .cer file to your Windows 11 development machine.
Step 2: Import the Certificate on the Client Machine
Run this Powershell cmdlet:
Import-Certificate -FilePath "C:\path\to\sqlservercert.cer" -CertStoreLocation Cert:\LocalMachine\Root
Step 3: Verify and Test
- Restart your .NET app (or the process) to ensure it picks up the cert store changes.
- Run your code again with the original connection string
TrustServerCertificate=False. It should now connect successfully.
This aligns with recent updates in SQL client drivers that default to requiring encryption and certificate validation, unlike older versions which did not validate certificates if encryption was enabled. However, I would like to recommend you try the option 1 and 2 first to see if the issue can be resolved.
All of the methods I’ve shared are based on my own research and testing within my environment. While I hope they’re helpful, I want to be transparent that I can’t guarantee they’ll work exactly the same in your setup, as results may vary depending on different configurations and system environments.
For reference, you may consult the following resource:
I sincerely hope this information partially clarifies your situation and assists you in planning your solution. Please know that while our initial response might not resolve the issue right away, your input is incredibly valuable. With a bit more detail, we’ll work together to find the best solution for you.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.