Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

737
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda