I am getting started with dotConnect and am quite happy with the functionality. I am connecting to a Galera cluster with 3 servers, if one of them is unavailable, the connection should move to the next server.
At the moment this is done by using a local load balancer (pen) which does the job nicely, but I would like to move away from it as it is an additional tool I have to use.
My code for the initial evaluation was this:
Code: Select all
public Database()
{
_conn = new MySqlConnection()
{
LocalFailover = true,
ConnectionString = GetConnectionString("ConnString"),
};
_conn.ConnectionLost += _conn_ConnectionLost;
}
private int errc = 0;
private void _conn_ConnectionLost(object sender, ConnectionLostEventArgs e)
{
if (errc++ > _maxretry)
{
e.RetryMode = RetryMode.Raise;
return;
}
if (e.Cause == ConnectionLostCause.Execute)
{
if (e.Context == ConnectionLostContext.None)
e.RetryMode = RetryMode.Reexecute;
else
e.RetryMode = RetryMode.Raise;
} else {
e.RetryMode = RetryMode.Raise;
}
}
Code: Select all
private void _conn_StateChange(object sender, StateChangeEventArgs e)
{
if (e.CurrentState.HasFlag(ConnectionState.Open)) errc = 0;
}
I tried setting the KeepAlive paramter in the connection string and also the PingInterval parameter in the connection object. Both settings did not change the behaviour.
Is there any way to disable this behaviour?
Bonus-Question: If I want to replace the external load balancer with the option to write multiple hosts in the connection string, how do I handle the switch to the next server? Do I need to do that in the ConnectionLost EventHandler?
Regards
Manuel