[Solved] C# connecting to MySQL database reports an error

C# is fine when calling mysql.data.dll to connect to the local database, but it reports an error when connecting to the mysql server on a remote Linux server
Error log, current connection string
System.Security.Authentication.AuthenticationException: Authentication to host ‘xxx.xxx.xxx.xx’ failed.
at MySql.Data.Common.Ssl.StartSSL(Stream& baseStream, Encoding encoding, String connectionString)
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()

<add key="dbString" value="server=localhost;port=3306;user=root;password=root; database=id3net" />

If the host does not support SSL connection, then SSL connection will not be used

Solution: add sslmode = none after the connection string.

<add key="dbString" value="server=localhost;port=3306;user=root;password=root; database=id3net;SslMode=none" />


Read More: