SqlException - The certificate chain was issued by an authority that is not trusted

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
Rawaj
User
Posts: 5

SqlException - The certificate chain was issued by an authority that is not trusted

Post by Rawaj »

When I upgraded to 2022, I always getting the following error:
SqlException: 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.)
Is there any configuration I have to do it in v2022 to get rid of this problem


MichaelG
User
Posts: 1110

Post by MichaelG »

Please read Database_Connecting example in the documentation:
https://aspnetmaker.dev/docs/#/customscripts.html


Rawaj
User
Posts: 5

Post by Rawaj »

Problem solved by the following :

public void Database_Connecting(ref string connstr) {
    
    connStr=connStr + "TrustServerCertificate=True;";
}

Thanks


darkdragon
User
Posts: 150

Post by darkdragon »

On a project converted from ANM2019 to ANM 2022.1, this part of code is not being added to appsettings.json or appsettings.Development.json:

public void Database_Connecting(ref string connstr) {

     connstr += "TrustServerCertificate=True;";

}

I have to rewrite each time the json files after each publish.


MichaelG
User
Posts: 1110

Post by MichaelG »

That's why you need to use the Database_Connecting server event as suggested.


darkdragon
User
Posts: 150

Post by darkdragon »

I was saying that I'm using that event.
But even so, the json files are not being updated, as suggested


JerryACSA
User
Posts: 15

Post by JerryACSA »

The Database_Connecting event doesn't modify the json file, but that's OK. When using the example code you gave above, each time ASP.NET Maker connects to the database, it calls Database_Connecting, which adds the parameter to the connection string in memory, which is then used to connect to the database. It worked for me.


darkdragon
User
Posts: 150

Post by darkdragon »

I get the error as stated in the first post of this thread, otherwise I would have not posted from beginning.
I simply have no idea how to fix this. Plus the fact in a development environment it makes no sense to implement SQL server certificates. This should not be enforced by a development tool.

For the moment being we’re dropping the migration to ANM2022, there are way too many breaking changes.


MichaelG
User
Posts: 1110

Post by MichaelG »

I was saying that I'm using that event. But even so, the json files are not being updated, as suggested

The Database_Connecting server event does not modify the appsettings json files. It modifies the connection string on the fly at run time. It should work as suggested by many other users on this same thread.


aspsteve
User
Posts: 52

Post by aspsteve »

I am getting the error message after logging in

The certificate chain was issued by an authority that is not trusted

Please advise on the correct syntax for the below.

// Database Connected event
public void Database_Connected(DbConnection conn) {
// Example:
//conn.Execute("Your SQL");
}

I changed to

//Database Connecting event
public void Database_Connecting(ref string connstr) {
// Check Info["id"] for database ID if more than one database
conn.Execute connstr += "TrustServerCertificate=True;";
}

and I am getting the following a build error message


MichaelG
User
Posts: 1110

Post by MichaelG »

Your codes are wrong. It should be just:

connstr += "TrustServerCertificate=True;";


Post Reply