steve_flynn
steve_flynn

Reputation: 45

Visual Studio Debug SQL Server Connection String - "SSL Provider, error 0 - The certificate chain was issued by an authority that is not trusted"

I recently wiped my laptop and reinstalled everything, including Visual Studio. Since doing so, my connection string for an intranet web app (connecting to a local SQL Server DB) no longer works in debug...

<add name="Company Database" connectionString="Data Source=Server\Instance;Initial Catalog=&quot;DBName&quot;;Persist Security Info=True;User ID=User;Password=Pass" providerName="System.Data.SqlClient" />

It works fine when deployed to a server, but when I try to run the app in debug I get the error "SSL Provider, error 0 - The certificate chain was issued by an authority that is not trusted". The posts I've found matching this error typically suggest to use (with caution for an external facing app) encrypt=false or TrustServerCertificate=true. When I try these, the text is underlined in green and tooltip displays "the encrypt attribute is not allowed". Have tried updating "System.Data.SQLClient" to "Microsoft.Data.SQLClient" but this doesn't appear to make any difference. Can anyone assist please? Thanks

Upvotes: 0

Views: 2377

Answers (3)

Check the "Trust server certificate" and press the Connect button.

SSMS Login

Upvotes: 1

Muhammad Abbas
Muhammad Abbas

Reputation: 1

I got resolved the issue using Self-Signed Certificate Using IIS Manager

Steps to Resolve the Error

Step 1. Generate a Self-Signed Certificate Using IIS Manager

  1. Open IIS Manager.
  2. In the left-hand tree, select your server node.
  3. Double-click Server Certificates in the middle pane.
  4. In the Actions pane on the right, click Create Self-Signed Certificate.
  5. Enter a friendly name for your certificate (e.g., SQLServerCert) and click OK.

Step 2. Bind the Certificate to SQL Server

  1. Open SQL Server Configuration Manager:

    • For Windows 11/10: Search for it in the Start menu.
  2. Expand SQL Server Network Configuration.

  3. Select Protocols for [Your SQL Instance Name].

  4. Right-click Properties for the protocol named TCP/IP and confirm it's Enabled.

  5. Go back to SQL Server Configuration Manager and select the SQL Server [Your SQL Instance Name] node in SQL Server services.

  6. Open the Certificate tab:

    • From the drop-down, select your self-signed certificate (e.g., SQLServerCert).
  7. Apply and restart the SQL Server service for the changes to take effect.

Upvotes: 0

Karim Hassan
Karim Hassan

Reputation: 1

add these two properties to your connection string: TrustServerCertificate=True;Encrypt=False

Upvotes: -1

Related Questions