Last post Mar 01, 2016 09:03 AM by Yohann Lu
Feb 29, 2016 12:47 PM|mazhar1783|LINK
am working on a asp.net mvc project. I want to know how can I change/switch database with new database during the setup of application (by client itself ) without running the migrations manually on the new database.
I want to change the database name in the connection string and that's it. My project should configure and works well with the new database.
Please suggest a solution.
Mar 01, 2016 09:03 AM|Yohann Lu|LINK
I want to know how can I change/switch database with new database during the setup of application (by client itself ) without running the migrations manually on the new database.
You can try the following suggestion.
1: You can create a constructor that takes a connection string as parameter like below.
public WMSEntities(string connStringName): base("name=" + connStringName)
2: Add the other connection string in Web.Config.
<add name="olddatabase" connectionString="data source=sql;initial catalog=OLDDB;userid=123;password=123/>
<add name="newdatabase" connectionString="data source=sql;initial catalog=NEWDB;userid=123;password=123/>
3: Then, when you connect to a database, you can call below method, passing the connetionString name as parameter.
public string GetPOVendorList(string connectionStringName)
using (WMSEntities db = new WMSEntities(connectionStringName))
vendorList = db.v_POVendor.ToList();
The following information for your reference.
Code First Migrations with an existing database:
Entity Framework Code First and Code First Migrations for Oracle Database: