Bug #117944 Unable to connect to any of the specified MySQL hosts.
Submitted: 11 Apr 10:26 Modified: 11 Apr 12:18
Reporter: RAFAEL ANTONIO VENTURA DIAZ Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:8.3.0.0, 9.2.0 OS:Windows (Windows (Windows Server 2022 Datacenter))
Assigned to: CPU Architecture:x86
Tags: MySql.Data, SSL

[11 Apr 10:26] RAFAEL ANTONIO VENTURA DIAZ
Description:
For Connection String shown below, MYSQL .NET connector failed with error message "Unable to connect to any of the specified MySQL hosts." when connection is set to verify CA with client PEM certificates.

Connection is successful when user servicenow does not REQUIRE SSL.

server=10.9.47.69@gemalto.com;
user id=servicenow;
password=#########;
database=#########;
sslmode=VerifyCA;
certificatefile=S:\Keys\SNOW\ca-cert.pem;
sslcert=S:\Keys\SNOW\client-cert.pem;
sslkey=S:\Keys\SNOW\client-key.pem

Destination server:
Type: MariaDB server version 10.6
User: servicenow with SSL REQUIRED

Full Stack trace:
MySql.Data.MySqlClient.MySqlException
  HResult=0x80004005
  Message=Unable to connect to any of the specified MySQL hosts.
  Source=MySql.Data
  StackTrace:
   at MySql.Data.MySqlClient.NativeDriver.<OpenAsync>d__38.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at MySql.Data.MySqlClient.Driver.<OpenAsync>d__76.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySql.Data.MySqlClient.Driver.<CreateAsync>d__74.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at MySql.Data.MySqlClient.Driver.<CreateAsync>d__74.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySql.Data.MySqlClient.MySqlPool.<CreateNewPooledConnectionAsync>d__31.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySql.Data.MySqlClient.MySqlPool.<GetPooledConnectionAsync>d__30.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySql.Data.MySqlClient.MySqlPool.<TryToGetDriverAsync>d__34.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at MySql.Data.MySqlClient.MySqlPool.<GetConnectionAsync>d__35.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySql.Data.MySqlClient.MySqlConnection.<OpenAsync>d__97.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at ST_9f9c558389fc4b93b829725aa7d075c0.ScriptMain.Main() in c:\Users\10062563\AppData\Local\Temp\3\Vsta\34724e1aa4194105ae79a88f474df478\ScriptMain.cs:line 146

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
ArgumentException: The host name or IP address is invalid.

How to repeat:
Configure a MariaDB V10.6 DB instance
Generate SSL certificates for server/client
Create a database
Create user servicenow with REQUIRE SSL
Copy SSL client certificate on client side:

Install MySQL .NET connector v8.3 on client side

Implement code  using C# 2022

Add MySQL client as a Reference: MySql.Data
Path: C:\Windows\Microsoft.NET\assembly\GAC_MSIL\MySql.Data\v4.0_8.3.0.0__c5687fc88969c44d\MySql.Data.dll
Version: 8.3.0.0

                    MySqlConnectionStringBuilder mySqlConnectionStringBuilder = new MySqlConnectionStringBuilder
                    {
                        Server = "10.9.47.69@gemalto.com",
                        UserID = "servicenow",
                        Password = "#####################",
                        Database = "#####################",
                        SslMode = MySql.Data.MySqlClient.MySqlSslMode.VerifyCA,
                        SslCa = @"S:\Keys\SNOW\ca-cert.pem",
                        SslCert = @"S:\Keys\SNOW\client-cert.pem",
                        SslKey = @"S:\Keys\SNOW\client-key.pem"
                    };
                using (MySql.Data.MySqlClient.MySqlConnection sqlConnection = new MySql.Data.MySqlClient.MySqlConnection(mySqlConnectionStringBuilder.ToString())
                    )
                {
                    sqlConnection.Open();
                    sqlConnection.Close();
                }
[11 Apr 12:18] MySQL Verification Team
Hello RAFAEL,

Thank you for the report and test case.

regards,
Umesh
[25 Apr 16:57] MySQL Verification Team
Hello RAFAEL,

Looks like I made a mistake while verifying, due to wrong host I was getting the same error which you observed but when Developer pointed me my mistake and after correcting I'm not getting any issues. 

-- user

mysql> create user 'ushastry'@'%' identified by 'mysql123' REQUIRE SSL;
Query OK, 0 rows affected (0.03 sec)

mysql> grant all on test.* to 'ushastry'@'%';
Query OK, 0 rows affected (0.01 sec)

-- VS 2022, C/NET 9.2.0 and MySQL Server 8.0.41

using MySql.Data.MySqlClient;
using System;

namespace Bug117944
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hellow World"); 
            MySqlConnectionStringBuilder mySqlConnectionStringBuilder = new MySqlConnectionStringBuilder
            {
                Server = "172.27.X.Y",
                UserID = "ushastry",
                Password = "mysql123",
                Database = "test",
                SslMode = MySql.Data.MySqlClient.MySqlSslMode.VerifyCA,
                SslCa = @"D:\ushastry\mysql-8.0.41-winx64\data\ca-cert.pem",
                SslCert = @"D:\ushastry\mysql-8.0.41-winx64\data\client-cert.pem",
                SslKey = @"D:\ushastry\mysql-8.0.41-winx64\data\client-key.pem"
            };
            using (MySql.Data.MySqlClient.MySqlConnection sqlConnection = new MySql.Data.MySqlClient.MySqlConnection(mySqlConnectionStringBuilder.ToString())
                )
            {
                sqlConnection.Open();
                sqlConnection.Close();
            }
        }
    }
}

--
Build started at 4:49 PM...
1>------ Build started: Project: Bug117944, Configuration: Release Any CPU ------
1>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.
1>Bug117944 -> D:\ushastry\Connectors\.NET\Bug117944\bin\Release\net9.0\Bug117944.dll
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 4:49 PM and took 00.457 seconds ==========

Hellow World

D:\ushastry\Connectors\.NET\Bug117944\bin\Release\net9.0\Bug117944.exe (process 21124) exited with code 0 (0x0).
Press any key to close this window . . .

regards,
Umesh

regards,
Umesh
[29 Apr 6:52] Carlos Martinez Alvarez
Hello,
As seen in your response, the difference between our issue and the test made by your team seems to be the version of database used.

In our case we specified a MariaDB 10.6, whilst in your tests you connected to a MySQL 8.0.41.

We're not sure if this difference between databases and versions may be causing the different outcomes.

If you were so kind to test that connection to the same database and version in our scenario, we'd appreciate it.

Best regards.