How do I modify which connection string a model uses?

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
extrakun
Posts: 22
Joined: Wed 20 Apr 2011 06:02

How do I modify which connection string a model uses?

Post by extrakun » Thu 21 Apr 2011 05:58

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?

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Thu 21 Apr 2011 11:51

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")) {
  //...
}


Post Reply