1 Run Application
2. Create Context
dbContext = new DBFirstContext();
3 Change App.config connection string for Entity FrameWork Object
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// change ConnectionString in App.Config for Entity FrameWork Object....
//.....
config.Save();
ConfigurationManager.RefreshSection("connectionStrings");
And now if I create
dbContext = new DBFirstContext();It use sourse unchanged connectionString, as it was at starting application. If Close and then restart the application - new dbContext will be created by using modified connectionString.
PS: I don't want to passing new connection string for create new dbContext by using constructor like this:
public DBFirstContext(string sConnectionString)
: base(sConnectionString)
I need to create dbContext by using default constructor, and that it take a new (changed) connection string from the app.config without restarting the application. Is it possible?
Thank!