1

I have master and slave database. when master is down, slave will automatically set as master. Both are in different servers. I am using MySQL server.

I am using master database connection with master server IP address and credentials as connection string in my c# application.

How to update the DB connection string automatically to Slave server when the Master server fails? What are the conditions that the C# program switch from the Master server to the Slave server?

I am using entity framework to connect to the database. Could anyone please help me to find out a solution.

  • Do you want to change connection string in realtime? Maybe this could help http://stackoverflow.com/questions/36816215/dynamically-change-connection-string-in-asp-net-core – trinvh Apr 25 '17 at 13:33

2 Answers2

1

Then you should specify the server names in the connection string like below. Check on MySQL Connection Strings

Server=master_server,slave_server;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Rahul
  • 76,197
  • 13
  • 71
  • 125
0

You can add 2 connection strings with different names in the app.config or web.config. Then the DbContext should receive the name of the connection string to connect. Then you only have to create a new DbContext with the slave connection string name as the constructor parameter.

aperezfals
  • 1,341
  • 1
  • 10
  • 26