Here is the connection strings in appsettings.json file.
appsettings.json
"ConnectionStrings": {
"DefaultConnection": "Server=DESKTOP-11G3852\\SQLEXPRESS;Database=MyDB;Trusted_Connection=True;MultipleActiveResultSets=true",
"OfficeConnection": "Server=DESKTOP-DTUS54A;Database=MyDB;Trusted_Connection=True;MultipleActiveResultSets=true",
"LappyConnection": "Server=DESKTOP-J8PN84H;Database=MyDB;Trusted_Connection=True;MultipleActiveResultSets=true"
}
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
.....
}
Here problem is, each time when I change my machine I have to manually set connection in Sratup.cs file. Here you can see I set "DefaultConnection".
I want solution like I have number of connection strings in appsetings.json file(right now here I have 3 connection strings) and it will check connection is established with first connection string(DefaultConnection) or not.
If not then it will start establish connection with second connection string(OfficeConnection).
If connection establish successfully then my website should continue with second connection string(OfficeConnection).
Extra: If possible my migration also needs to apply with successfully connected connection string.