C# Connect MYSQL Error: MySql.Data.MySqlClient.MySqlException:“SSL Connection error.”

To solve this exception, you need to ensure normal operation

MySqlConnection conn;// Represents an open connection to a MySQL database. This class cannot be inherited
MySqlCommand comm;// Represents the SQL statement to execute on the MySQL database. This class cannot be inherited
MySqlDataAdapter adapter;// Represents a set of data commands and database connections for populating datasets and updating MySQL databases. This class cannot be inherited.

The exceptions of error reporting are as follows

MySql.Data.MySqlClient.MySqlException:“SSL Connection error.”

IOException: unable to read data from the transport connection: an established connection was aborted by the software in your host

Connection string (exception)

string mysqlconn = "server=127.0.0.1;port=3306;user=root;password=root;database=wpfstudy;";

Connection string (normal)

string mysqlconn = "server=127.0.0.1;port=3306;user=root;password=root;database=wpfstudy;SslMode = none;";

Add the following statement to the connection string

SslMode = none;

When using. Net/C # to operate MySQL database, the default value of sslmode is preferred. If the server supports it, please use SSL

SSL (secure socket layer) uses data encryption, authentication and message integrity verification mechanisms to provide security assurance for application layer protocols based on reliable connections such as TCP. If the user’s transmission is not through SSL, the data in the network is transmitted in plaintext, which brings an opportunity for people with ulterior motives. Therefore, many large websites now have SSL enabled. Similarly, in our database, if the client connects to the server to obtain data instead of using SSL connection, the data may be stolen during transmission.

The functions provided by SSL protocol mainly include:

1. Confidentiality of data transmission: use symmetric key algorithm to encrypt the transmitted data
2. Authentication mechanism: use digital signature method to authenticate the server and client based on certificate, and the authentication of the client is optional
3. Message integrity verification: MAC algorithm is used to verify message integrity during message transmission.

Read More: