Page 1 of 1

How do I modify which connection string a model uses?

Posted: Thu 21 Apr 2011 05:58
by extrakun
For my project I have to travel between the client's site and my workplace, so I have to test my code on their site's database too.

My purpose is to have 2 connection strings listed in web.config, one for my workplace, and one for the client's site. Remote connection is not possible due to security issues.

How do I modify which connection string my model is using?

Posted: Thu 21 Apr 2011 11:51
by AndreyR
Create two connection string entries in the application configuration file, e.g.:

Code: Select all

    
    
Then create the contexts in the following way:

Code: Select all

using(MyEntities db = new MyEntities("name=ConnString")) {
  //...
}
using(MyEntities  db_client = new MyEntities ("name=ConnString_Client")) {
  //...
}