question

AlvordTimothy-4979 avatar image
0 Votes"
AlvordTimothy-4979 asked MichaelPerry-0614 published

VS2022 connecting to SQLServer 2014 Database

Hi,
We currently have a 2014 SQL Server Database that we currently are connecting to using VS2012. The code we are using comes from the older 4.5 .Net libraries System.Data.SQLClient. The following is the code it's using:

 SqlConnection conn = new SqlConnection();
 conn.ConnectionString = "Data Source=la04sqlpres01;Initial Catalog=FPY;User ID=UserName;Password=password";
 conn.Open();

I tried using the same code with the new VS2022 .Net 6.0 library Microsoft.Data.SQLClient. When it tries to execute the conn.Open command it gets the following error:


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

Anyone have any idea what the ConnectionString needs to be now or what the new code might look like?

dotnet-sqlclient
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered MichaelPerry-0614 published

the newer libraries use ssl (in-transit encrypted) by default. The error means the ssl certificate on the Sqlserver is not trusted by your machine.

the correct fix is to use a trusted ssl certificate on the Sqlserver

you have two hack options in the connection string:

1) disable ssl: Encrypt=False;

2) disable certificate validation: TrustServerCertificate=False;

microsoft recommends the second over the first


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Option 2 didn't work for me, but Option 1 did.

0 Votes 0 ·

Option 2 should be TrustServerCertificate=True

0 Votes 0 ·