1 Attachment(s)
The certificate chain was issued by an authority that is not trusted
I have been wrestling with this error and can't seem to find a solution. I've tried downloading versions 17 & 18 of the Microsoft ODBC Driver for SQL Server and it's still not working. I have attached an screenshot of my code.
Attachment 188484
Re: The certificate chain was issued by an authority that is not trusted
If you are using SqlClient then odbc isn't getting involved, updating odbc drivers won't affect this.
https://learn.microsoft.com/en-us/tr...en-you-connect is probably worth a read though.
1 Attachment(s)
Re: The certificate chain was issued by an authority that is not trusted
Wow, I opened the MMC and there is NO list of Certs. See image below!
Attachment 188486
Re: The certificate chain was issued by an authority that is not trusted
If all you did was open MMC, then yeah, you aren't going to see certificates, or anything else for that matter.
Once MMC is opened, you need to click File->Add/Remove Snap-in, click the Add button, and select Certificates, and go from there.
1 Attachment(s)
Re: The certificate chain was issued by an authority that is not trusted
I see what your saying. Here is the result of doing as you said.
Attachment 188487
I also looked under the "Trusted Root Certification Authorities" and didn't see any cert that had SQL Server in in. I'm not sure what I'm looking for so it might be there and I just don't recognize it.
Re: The certificate chain was issued by an authority that is not trusted
https://stackoverflow.com/questions/...sted-when-conn
Based on the connection string, this appears to be your own PC that you are connecting to. Workarounds for non-production, non-publicly accessible systems would be to either set Trusted_Connection to false, or add TrustServerCertificate=True to the connection string.
Good luck.
Re: The certificate chain was issued by an authority that is not trusted
I added "TrustServerCertificate=True" and that worked...or at least allowed me to execute the program. However, the connection state is 0 (not openend).
And you are correct, it is my machine and I'm only using it to test things. I'm trying to get back into IT so I'm doing some self-training. Thanks for your help!
1 Attachment(s)
Re: The certificate chain was issued by an authority that is not trusted
I am using my laptop with a local instance of SQL Server 2019 and Visual Studio 2019 Community edition. I don't know what else to do with this issue. I don't know where the problem is. Here is my most recent code as well as an image.
Code:
//using System;
//using System.Collections.Generic;
//using System.ComponentModel;
using System.Data;
using Microsoft.Data.SqlClient;
//using System.Drawing;
//using System.Linq;
//using System.Text;
using System.Windows;
//using System.Threading.Tasks;
//using Prism.Services.Dialogs;
namespace WpfApp1
{
class DatabaseIO
{
DataSet ds;
SqlCommand sqlComm;
SqlParameter sqlParm;
SqlConnection sqlCnn;
public bool OpenDBConnection()
{
//string connectionString = "Server=BLAKES-PC;Database=Northwind;User Id='';Password='';Trusted_Connection=True;TrustServerCertificate=True;";
string connectionString = "Data Source = (local); Initial Catalog = Northwind;Integrated Security=SSPI;User Id='';Password=''";
using (SqlConnection sqlCnn = new SqlConnection(connectionString))
{
sqlCnn.Open();
MessageBox.Show("State: {0}", sqlCnn.State.ToString(), MessageBoxButton.YesNo, MessageBoxImage.Question);
if (sqlCnn.State.Equals("Open"))
{
return true;
}
return false;
}
}
//
//
//
public void GetStateAbbr(DataSet ds)
{
}
}
}
Attachment 188493
Re: The certificate chain was issued by an authority that is not trusted
What happens if you try adding both the "rusted_Connection=True;TrustServerCertificate=True" entries to the connection string for the local database?
Re: The certificate chain was issued by an authority that is not trusted
I tried adding those properties and it executed, however, the database still isn't open...
Re: The certificate chain was issued by an authority that is not trusted
Quote:
Originally Posted by
blakemckenna
I tried adding those properties and it executed, however, the database still isn't open...
So did you get a different error, or just no results?
Re: The certificate chain was issued by an authority that is not trusted
No results...I popup a messagebox saying "Database OPEN" or "Database CLOSED" and it comes up CLOSED.
Re: The certificate chain was issued by an authority that is not trusted
Quote:
Originally Posted by
blakemckenna
No results...I popup a messagebox saying "Database OPEN" or "Database CLOSED" and it comes up CLOSED.
Code:
sqlCnn.State.Equals("Open")
seems an unusual way of checking an enum, I suspect this is the problem. If you want to compare the status then just use
Code:
if(sqlCnn.State == ConnectionState.Open)
1 Attachment(s)
Re: The certificate chain was issued by an authority that is not trusted
I believe that worked but I can't tell because I'm throwing an exception and don't know why. I'm sure it's because of my lack of knowledge of C#. I'm trying to learn this language so I can re-enter the IT world. Here is the message I'm getting.
Attachment 188495
Re: The certificate chain was issued by an authority that is not trusted
Quote:
Originally Posted by
blakemckenna
I believe that worked but I can't tell because I'm throwing an exception and don't know why. I'm sure it's because of my lack of knowledge of C#. I'm trying to learn this language so I can re-enter the IT world. Here is the message I'm getting.
Attachment 188495
The image is a bit difficult to read, generally it is better to just put the error message itself into your post.
That seems a really strange exception to be thrown on such a simple line of code. Try putting a breakpoint on that line and step through the code, just to see what happens.
Although, you are also declaring a variable with the same name in the OpenDBConnection method - is this what you intended to do?