views:

57

answers:

1

Hello!

I have two connection strings (both in Web.Config: CS_Local and CS_Production) for my DBML (Linq to SQL).

In my Global.Asax/Application_Start I run some production preparation methods if the request is non-local (!HttpContext.Current.Request.IsLocal). Within that part, I'd also like to change the current connection string used by my DBML from the standard CS_Local to CS_Production.

How would I do that? Some help please..

+3  A: 

You can define the dbml context on the fly with:

string connectionString = HttpContext.Current.Request.IsLocal ? 
    ConfigurationManager.ConnectionStrings["CS_Local"].ConnectionString :
    ConfigurationManager.ConnectionStrings["CS_Production"].ConnectionString;
yourDataContext = new YourApplicationDataContext(connectionString);
Kelsey