Handling primary and secondary connection strings with Entity Framework Core

asp.net-core c# entity-framework entity-framework-core

Question

I have an application which is currently using DbContextPooling. I have been tasked with rotating primary and secondary connection strings. So is there a way of handling this in EF Core?

1
0
6/14/2019 4:38:18 PM

Popular Answer

Sure. It's even easy. It may be incompatible with DbContextPooling, however. You'll need to test.

On your DbContext implement OnConfiguring, acquire the correct connection string and use it.

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    var connectionString = ...;
    optionsBuilder.UseSqlServer(connectionString);
    base.OnConfiguring(optionsBuilder);
}
0
6/14/2019 8:09:03 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow