'C# MySQL SSL Connection Error when trying to use conn.Open()

For the past 3 days now I have been struggling with an issue with MySQL connector in C#. Basically, I follow the MySQLConnector tutorial to open my connection in order to send data, but when I get to the MySQLConnection.Open() method, my code throws a SSL Connection error. Here is the code:

public async void SQLInsert()
        {
            string connStr = "Server=echstreme.de;User=c1Look;Database=c1Look;Port=3306;Password=redacted;";
            MySqlConnection conn = new MySqlConnection(connStr);

            try
            {
                await SendEmbedMessage("MySQL", "Attempting to connect to database");
                conn.Open();
                await SendEmbedMessage("MySQL", "Connection to Database Successful");
                MySqlCommand cmd = new MySqlCommand(sqlQuery, conn);

                cmd.ExecuteNonQuery();


                conn.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

I have tried using both the Domain "echstreme.de" and the IP address, however both throw similar errors.

EDIT: THIS HAS BEEN FIXED Fix => "Server=echstreme.de;Port=3306;Database=c1Look;Uid=c1Look;Pwd=;SSL Mode =None";

Here is the complete error message for anyone needing it

MySql.Data.MySqlClient.MySqlException (0x80004005): SSL Connection error.
 ---> System.AggregateException: One or more errors occurred. (The handshake failed due to an unexpected packet format.)
 ---> System.IO.IOException: The handshake failed due to an unexpected packet format.
   at System.Net.Security.SslStream.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.PartialFrameCallback(AsyncProtocolRequest asyncRequest)
--- End of stack trace from previous location where exception was thrown ---
   at System.Net.Security.SslStream.ThrowIfExceptional()
   at System.Net.Security.SslStream.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.Security.SslStream.EndProcessAuthentication(IAsyncResult result)
   at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)
   at System.Net.Security.SslStream.<>c.<AuthenticateAsClientAsync>b__64_2(IAsyncResult iar)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at MySql.Data.Common.Ssl.StartSSL(Stream& baseStream, Encoding encoding, String connectionString)
   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()
   at Bot.Admins.AdminCommands.SQLInsert() in C:\Users\Owner\source\repos\Bot\Bot\Admins\AdminCommands.cs:line 71


Solution 1:[1]

If your host doesn't support SSL you can use SSL Mode options, None or Required.

Connection string must be like this

"Server=echstreme.de;User=c1Look;Database=c1Look;Port=3306;Password=redacted;SSL Mode=None"

Solution 2:[2]

When you go on mysql connection strings

You will see connection string with TCP port in it like this, try with this connection string construction:

Server=myServerAddress;Port=1234;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

Also are you sure you are using right port?

Solution 3:[3]

you need change your drive connector to correct version of you database. if your use mysql 8 you need to use connector v8 and vice versa

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Batuhan
Solution 2 Xyloto
Solution 3 Michael Rodrigues