[英]How can I switch between 2 Connection Strings in my Web.Config (Activate one for DBML)
I have two connection strings (both in Web.Config: CS_Local and CS_Production) for my DBML (Linq to SQL). 我的DBML(Linq to SQL)有两个连接字符串(在Web.Config中:CS_Local和CS_Production)。
In my Global.Asax/Application_Start I run some production preparation methods if the request is non-local (!HttpContext.Current.Request.IsLocal). 如果请求不是本地请求(!HttpContext.Current.Request.IsLocal),则在Global.Asax / Application_Start中运行一些生产准备方法。 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.
在那部分中,我还想将DBML使用的当前连接字符串从标准CS_Local更改为CS_Production。
How would I do that? 我该怎么做? Some help please..
请一些帮助..
You can define the dbml context on the fly with: 您可以使用以下方法动态定义dbml上下文:
string connectionString = HttpContext.Current.Request.IsLocal ?
ConfigurationManager.ConnectionStrings["CS_Local"].ConnectionString :
ConfigurationManager.ConnectionStrings["CS_Production"].ConnectionString;
yourDataContext = new YourApplicationDataContext(connectionString);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.