Sven Rademacher
Sven Rademacher

Reputation: 37

Multiple hosts in connection string

when iam trying to add 2 hosts to my programm so i can reach the server from within / without local workgroup by using domain or ip, i allways get the message that i could not reach one of those servers.

Using only one of the hosts results in success, however using both does not

String connString = "Server=hpscloud.de:3306,192.168.10.1:3306;Database=" + database + ";uid=" + username + ";password=" + password;

Can you guys tell me what iam doing wrong ?

Upvotes: 0

Views: 3440

Answers (2)

Bradley Grainger
Bradley Grainger

Reputation: 28207

Oracle's MySql.Data claims to support multiple hosts in its documentation:

Multiple hosts can be specified separated by commas.

(The documentation linked in the other answer that says & has a typo and is incorrect.)

Unfortunately, support for comma-separated hosts has been broken for many years: bug 81650.

To get support for this feature, switch to MySqlConnector (which fixes this and many other MySql.Data bugs).

Note that the port can't be specified as part of the hostname; it has to be specified with the Port= option (or omitted since 3306 is the default). Your connection string should be:

String connString = "Server=hpscloud.de,192.168.10.1;Database=" + database + ";uid=" + username + ";password=" + password;

Also check out the LoadBalance option to control how connections are made across the servers you specify.

Upvotes: 1

mnieto
mnieto

Reputation: 3874

Server names should be separated by the & char

As per documentation

The name or network address of the instance of MySQL to which to connect. Multiple hosts can be specified separated by &. This can be useful where multiple MySQL servers are configured for replication and you are not concerned about the precise server you are connecting to. No attempt is made by the provider to synchronize writes to the database so care should be taken when using this option.

See https://dev.mysql.com/doc/dev/connector-net/6.10/html/P_MySql_Data_MySqlClient_MySqlConnection_ConnectionString.htm for further information

Upvotes: 0

Related Questions