I’m running the following code…
using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["db-connection"].ConnectionString))
{
connection.Open();
var command = new SqlCommand("SELECT @@SERVERNAME",connection);
using (var reader = command.ExecuteReader())
{
reader.Read();
return reader[0].ToString();
}
}
…as a sanity check to return the name of the DB server this application is pointing to. There are two DB servers (DB00 and DB01) and they are behind HAProxy which is setup to failover to DB01 if DB00 is unavailable.
The connection string looks like this:
<add name="db-connection"
connectionString="User Id=USER_ID; Password=PASSWORD; Initial Catalog=the-database; Server=load-balancer.is.here,59281; Application Name=My.Application.Name;Min Pool Size=5;Max Pool Size=500;Connect Timeout=10;Connection Lifetime=29;" />
The problem we’re experiencing is this:
- we failover to DB01 (currently done by editing the HAProxy config, making DB00 the backup and then reloading HAProxy)
- the SELECT code (the code at the begining of this question) should now return DB01 as the servername but it doesn’t, it still returns DB00
- this means our SQLConnections still seem to be pointing to the wrong DB
- the problem persists until we restart the mono process on the box the code is hosted
- now the sanity check code returns the correct servername – DB01
Any ideas what this could be? Is it possibly a mono connection pooling issue?
EDIT
HAProxy config as requested:
1 global
2 maxconn 4096
3 daemon
4
5 defaults
6 mode tcp
7 #mode http
8 contimeout 5000
9 clitimeout 50000
10 srvtimeout 50000
11
12
13 frontend blahblah
14 bind *:59283
15 mode tcp
16 default_backend sql-server-lockertest
17
18 backend sql-server-lockertest
19 balance roundrobin
20 server james 10.0.10.217:1433 check maxconn 32 rise 3 fall 3
21 server andres 10.0.10.226:1433 check maxconn 32 rise 3 fall 3 backup
Regards,
James
It turns out Mono didn’t support yet the “Connection Lifetime” parameter in connection strings.
But we just fixed it and proposed a pull request:
https://github.com/mono/mono/pull/517