Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

745
Views
Sudden - 'The certificate chain was issued by an authority that is not trusted in Microsoft.Data.SqlClient' in working project

I have an ASP.Net Webforms website running in IIS on a Windows Server. Also on this server is the SQL server.

Everything has been working fine with the site but now I am seeing issues with using a DataAdapter to fill a table.

So here is some code, please note it's just basic outline of code as actual code contains confidential information.

public List<Summary> Fetch(string Connection, int parameter1, int parameter2, bool parameter3)
{
     List<Summary> collection = new List<Summary>();

     using (SqlConnection dbConnection = new SqlConnection(Connection))
     {
        using (SqlCommand dbCommand = dbConnection.CreateCommand()) // Result is complex
        {
            dbCommand.CommandType = CommandType.StoredProcedure;
             
            //
            // Code to add parameters and set commandText goes here
            //

            using (SqlDataAdapter da = new SqlDataAdapter(dbCommand))
            {
                DataTable table = new DataTable();
                DataRow row;

                try
                {
                  da.Fill(table);
                }
                catch(Exception ex)
                {
                   // Log error
                }
                
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    row = table.Rows[i];
                    Summary data = Populate(row);
                    collection.Add(data);
                }
            }
         }
     }
     return collection;
}

The above is in a library and is called like this in the Web Forms site.

var Summaries = MyLibrary.Fetch(ConnectionString, 1, 111, false);

So as I say, everything was working fine. Now, all of a sudden the above has stopped working and Summaries is always empty.

To investigate I tried the following.

Created a test using xUnit with the same parameters used by the website. These were captured during debugging to ensure they matched. The result returned 1 item.

I then ran the stored procedure in SQL management Studio and it matched the xUnit test with 1 item returned.

I then checked SQL Profiler and this is where things seemed a little odd. Nothing was being recorded in the trace when the web-forms was calling the library.

So both the web-site and xUnit test were using the same library, passing the same parameters and yet one worked and the other didn't... very odd.

As a last resort, I added the library project to the Web Forms project and proceeded to debug through that... then I found the error.

da.Fill(table);

The above line generated the following exception.

Exception thrown: 'Microsoft.Data.SqlClient.SqlException' in Microsoft.Data.SqlClient.dll 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.)

Having a look around here on stack, I saw many responses with I need to install a certificate.

My question is, if this is the case then why and why now? Nothing has changed in the code from when it was working till now. The web-site and SQL server are on the same windows server. Also, why does the xunit test work without it and the website does not when I am debugging on the same machine!

The only items that I now has changed is install of .Net 6 and patch Tuesday resulted in some updates and a restart of the server.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

I hit this issue as well. Net 6.0

It suddenly started occurring when I upgraded Microsoft.EntityFrameworkCore.SqlServer

FROM Version="6.0.0" to Version="6.0.1"

I added Encrypt and TrustServerCertificate to connection string.

data source=(local);Initial Catalog=XXXXXXX;Trusted_Connection=True;MultipleActiveResultSets=True;Encrypt=True;TrustServerCertificate=True

over 4 years ago · Santiago Trujillo Report

0

Microsoft.Data.SqlClient 4.0 is using ENCRYPT=True by default. Either you put a certificate on the server (not a self signed one) or you put

TrustServerCertificate=Yes;

on the connection string.

over 4 years ago · Santiago Trujillo Report

0

I suddenly got the same problem when first upgrading Microsoft.Data.SqlClient to 4.x.x. I reverted back to 2.0.1 and the same problem was present.

I then removed all "bin" and "obj" folders for each project. And then executed a "dotnet restore". After that it worked as before.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!