我怎样才能在我的web.config 2连接字符串之间切换(激活一个DBML) [英] How can I switch between 2 Connection Strings in my Web.Config (Activate one for DBML)
问题描述
我有两个连接字符串(无论是在Web.Config中:CS_Local和CS_Production)为我的DBML(LINQ到SQL)
I have two connection strings (both in Web.Config: CS_Local and CS_Production) for my DBML (Linq to SQL).
在我的Global.asax /我的Application_Start运行部分生产preparation方法,如果要求非本地(!HttpContext.Current.Request.IsLocal)。在这一部分,我也想改变从标准CS_Local到CS_Production使用我的DBML当前连接字符串。
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..
推荐答案
您可以定义与飞dbml的背景:
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);
这篇关于我怎样才能在我的web.config 2连接字符串之间切换(激活一个DBML)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!