Connect with MySqlConnector [.NET]

Hello all,
I tried to connect to mysql db (free instance) and I cannot find any sort of documentation (nor stackoverflow answers) for setting the right connection string.
I’m trying with MySqlConnector v2.3.7 (latest):

Database=defaultdb;Server=mysql-##############.aivencloud.com;Port=######;Uid=########;Pwd=########;SslMode=VerifyCA;SslCa=ca.pem;

but I got he error:
System.FormatException: ‘Expected to read 0x0A but got 0x0B’

on connection.Open().

Am I missing something?

ps.
don’t try with official MySql.Data unless you cannot use v8 or later (SslCa support is not active for 5.x)

ps2.
the same behaviour with “SslMode=Required;” - I’ll look forward for your help!

It appears the issue might be due to incorrect line endings or encoding in your connection string. Ensure consistent line endings (\n or \r\n) and proper encoding. Additionally, confirm compatibility between the version of MySqlConnector and your MySQL instance. Double-check SSL configuration, including the location and permissions of the SSL certificate (ca.pem). For more insights, consider implementing detailed error handling or seeking support from MySqlConnector’s community forums or your MySQL hosting provider.

Best Regard
Danish hafeez | QA Assistant
ICTInnovations

Thanks for your reply. Yes, I checked:

  • the pem path, which is ok
  • the sslmode is required or verifyCA
  • I tried connecting with charset = utf8mb4 . Which is the right encoding?

Same error by my side.

In the server logs I get:
[Warning] [MY-013712] [Server] No suitable ‘keyring_component_metadata_query’ service implementation found to fulfill the request.

What is this? How can I handle it? It seems a server-side problem.

Also, I can share the error stack in MySqlConnector:

   at MySqlConnector.Protocol.Serialization.ByteArrayReader.ReadByte(Byte value)
   at MySqlConnector.Protocol.Payloads.InitialHandshakePayload.Create(ReadOnlySpan`1 span)
   at MySqlConnector.Core.ServerSession.<ConnectAsync>d__103.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySqlConnector.Core.ConnectionPool.<ConnectSessionAsync>d__21.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at MySqlConnector.Core.ConnectionPool.<ConnectSessionAsync>d__21.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at MySqlConnector.Core.ConnectionPool.<GetSessionAsync>d__9.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at MySqlConnector.Core.ConnectionPool.<GetSessionAsync>d__9.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at MySqlConnector.MySqlConnection.<CreateSessionAsync>d__132.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at MySqlConnector.MySqlConnection.<OpenAsync>d__29.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySqlConnector.MySqlConnection.Open()

Out of curiosity, if you attempt to connect from the command line or from something like https://www.heidisql.com/ (Note: Not an endorsement, but the first thing that came up when I searched for Windows SQL clients), do you get the same results?

Trying to see if we can isolate this to a server problem vs. a problem with the way MySqlConnector is interfacing with the server.

HeidiSQL works fine. This is defintely something related to enconding, so I repeat the question: which is the right encoding to connect to Aiven?

Yeah, still working on tracking that answer down for you (I think most of our engineers are Linux folk :sweat_smile: ), but meanwhile I wanted to reduce the debugging surface area. :slight_smile: Thanks for confirming!

Hello,
I tried also MySql.Data, with not success. I got error:
Version string not in acceptable format

I’d stick on MySqlConnector instead, this is claimed to be a but on MySql.Data (see c# - MySql.Data.MySqlClient.MySqlException Version string not in acceptable format error while connecting to -log enabled instance - Stack Overflow)

I’ll look forward for your support on the previous question