VS2022 connecting to SQLServer 2014 Database

Alvord, Timothy 236 Reputation points
2022-03-11T22:01:27.547+00:00

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?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,692 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 55,601 Reputation points
    2022-03-11T22:24:18.23+00:00

    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


0 additional answers

Sort by: Most helpful