2010-05-21 27 views
0

2個連接字符串之間進行切換,我有兩個連接字符串(無論是在Web.Config中:CS_Local和CS_Production)爲我的DBML(LINQ到SQL)。我怎樣才能在我的web.config(激活一個DBML)

在我的Global.asax /我的Application_Start運行部分生產製備方法,如果請求非本地(!HttpContext.Current.Request.IsLocal)。在那部分中,我還想將我的DBML使用的當前連接字符串從標準CS_Local更改爲CS_Production。

我該怎麼做?一些幫助,請..

回答

4

您可以定義與飛dbml的背景:

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