10

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
1
  • 1
    Question is good, but versions info is missing. Commented Aug 19, 2021 at 10:17

3 Answers 3

33

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"
Sign up to request clarification or add additional context in comments.

3 Comments

Hey, sadly this threw the same error as I commented above.
Exact Solution! I was after this issue for a couple of weeks. Your solution worked for me
SSL Mode=None fixed it for me after MySql.Data stopped working after 8.0.27. I didn't see it mentioned in the 8.0.28 release notes but it would seem they changed the default in this version.
0

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?

6 Comments

Hey, trying the other construction did not work and left me with the same error as before. However, using the new string and changing the port to 8080 (as the title bar of the db says) the error changed to ``` MySql.Data.MySqlClient.MySqlException : Reading from the stream has failed. Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond```
Does guy in tutorial use echstreme.de as server? Can you provide link for tutorial which you learn?
Hey, no, echstreme.de was provided by my hosting provider. I am using the official MySQL Connector tutorial dev.mysql.com/doc/connector-net/en/…
Hey, it appears to have been fixed! Thank you for the help Fixing: "Server=echstreme.de;Port=3306;Database=c1Look;Uid=c1Look;Pwd=redacted;SSL Mode =None";
@Luke if SSL Mode solved your issue can you mark as solution my answer ?
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.