I have an application that can make a connection to a database. There are many instances of this database use by numerous sites. I want to use migration to update the database schema when the program loads. I have got this working. However, my connection string stored in app.config has been blanked out(by me) And I use a connection string builder to take the users login details and server/database username/password and alter the connection string within the dbcontext to connect to their own database.
Eg. source.Database.Connection.ConnectionString "TrustServerCertificate=False;Encrypt=true;Integrated Security =" + integratedSecuity + ";data source=" + Server + ";initial catalog=" + Database + ";persist security info=true;"+ ";MultipleActiveResultSets=True;App=EntityFramework\" providerName = \"System.Data.SqlClient";
I have utilized a snippet from Stackoverflow to check for changes in my entity framework on program start.
Db = Internal_ConnectionTools.ChangeDatabase(Db, Txt_Database.Text, Txt_Server.Text, Txt_User.Text,Txt_Password.Text);
LabDatabase LD = new LabDatabase(Db.Database.Connection.ConnectionString);
Database.SetInitializer<LabDatabase>(
new MigrateDatabaseToLatestVersion<LabDatabase, Configuration>());
LD.Database.Initialize(true);
The problem I am having is that it keeps pointing back to the connection string in my App.config file and throwing an error that the Initial catalogue has not been defined.(because there is nothing defined by design)
If I fill the app.config connection string with my credentials, my database updates as expected.
How can I ensure that Entityobject.Database.Initialize() will use my updated custom string and update the users database instead of defaulting to the App.config string?