| Bug #96561 | multiple hosts error(Unable to connect to any of the specified MySQL hosts.) | ||
|---|---|---|---|
| Submitted: | 16 Aug 2019 2:22 | Modified: | 16 Aug 2019 13:23 |
| Reporter: | black 无 | Email Updates: | |
| Status: | Duplicate | Impact on me: | |
| Category: | Connector / NET | Severity: | S3 (Non-critical) |
| Version: | 8.0.17 | OS: | Any |
| Assigned to: | CPU Architecture: | Any | |
[16 Aug 2019 11:58]
black 无
My temporary solution
MySQL.Data/src/common/StreamCreator.cs:
public static Stream GetStream(MySqlConnectionStringBuilder settings)
{
Exception exception = null;
string[] servers = settings.Server.Split(',');
settings = new MySqlConnectionStringBuilder(settings.ConnectionString);
foreach (string server in servers)
{
settings.Server = server;
try
{
switch (settings.ConnectionProtocol)
{
case MySqlConnectionProtocol.Tcp: return GetTcpStream(settings);
case MySqlConnectionProtocol.UnixSocket: return GetUnixSocketStream(settings);
case MySqlConnectionProtocol.SharedMemory: return GetSharedMemoryStream(settings);
case MySqlConnectionProtocol.NamedPipe: return GetNamedPipeStream(settings);
}
break;
}
catch (Exception e)
{
exception = e;
}
}
if (null != exception) throw exception;
throw new InvalidOperationException(Resources.UnknownConnectionProtocol);
}
[16 Aug 2019 13:23]
MySQL Verification Team
Hello black 无, Thank you for the report. Imho this is duplicate of Bug #81650, please see Bug #81650 Alternatively, you can try this - https://blogs.oracle.com/mysql/how-to%3a-using-replication-load-balancing-with-connectorne... regards, Umesh

Description: ConnectionString: "server=server1,server2,server3;" multiple hosts error(Unable to connect to any of the specified MySQL hosts.) How to repeat: using System; using MySql.Data.MySqlClient; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var conn1 = new MySqlConnection("server=server1;port=6446;user=root;password=123456;database=test;sslmode=none;"); conn1.Open(); // connection ok var conn2 = new MySqlConnection("server=server1,server2,server3;port=6446;user=root;password=123456;database=test;sslmode=none;"); conn2.Open(); // Unable to connect to any of the specified MySQL hosts. // StreamCreator.cs // GetTcpStream() // task = client.ConnectAsync(settings.Server, (int)settings.Port); // doc: Multiple hosts can be specified separated by commas. // settings.Server = "server1,server2,server3" ??? bug Console.WriteLine("Hello World!"); } } }