title: Sudden - 'The certificate chain was issued by an authority that is not trusted in Microsoft.Data.SqlClient' in working project
body: <p>I have an ASP.Net Webforms website running in IIS on a Windows Server.
  Also on this server is the SQL server.</p>
  <p>Everything has been working fine with the site but now I am seeing issues with using a DataAdapter to fill a table.</p>
  <p>So here is some code, please note it's just basic outline of code as actual code contains confidential information.</p>
  <pre><code>public List&lt;Summary&gt; Fetch(string Connection, int parameter1, int parameter2, bool parameter3)
  {
       List&lt;Summary&gt; collection = new List&lt;Summary&gt;();
  
       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 &lt; table.Rows.Count; i++)
                  {
                      row = table.Rows[i];
                      Summary data = Populate(row);
                      collection.Add(data);
                  }
              }
           }
       }
       return collection;
  }
  </code></pre>
  <p>The above is in a library and is called like this in the Web Forms site.</p>
  <pre><code>var Summaries = MyLibrary.Fetch(ConnectionString, 1, 111, false);
  </code></pre>
  <p>So as I say, everything was working fine. Now, all of a sudden the above has stopped working and <code>Summaries</code> is always empty.</p>
  <p>To investigate I tried the following.</p>
  <p>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.</p>
  <p>I then ran the stored procedure in SQL management Studio and it matched the xUnit test with 1 item returned.</p>
  <p>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.</p>
  <p>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.</p>
  <p>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.</p>
  <pre><code>da.Fill(table);
  </code></pre>
  <p>The above line generated the following exception.</p>
  <blockquote>
  <p>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.)</p>
  </blockquote>
  <p>Having a look around here on stack, I saw many responses with I need to install a certificate.</p>
  <p>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!</p>
  <p>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.</p>