0

如何提取以下連接字符串並將其應用到我的Linq上下文中?我知道Linq部分,但在System.Configuration部分很弱。從App.config獲取連接字符串並在Linq dataContext中使用它

<connectionStrings> 
     <!-- Production 

     <add name="Management_Report_Emailer.Properties.Settings.DWConnectionString" 
      connectionString="Data Source=prodSQL01;Initial Catalog=DW;Integrated Security=True" 
      providerName="System.Data.SqlClient" />--> 


     <!-- QA--> 

     <add name="Management_Report_Emailer.Properties.Settings.DWConnectionString" 
      connectionString="Data Source=qaSQL01;Initial Catalog=DW;Integrated Security=True" 
      providerName="System.Data.SqlClient" /> 
    </connectionStrings> 

回答

2
ConfigurationManager.ConnectionStrings("Management_Report_Emailer.Properties.Settings.DWConnectionString").ConnectionString 
+0

工作對我來說,只是不得不更換括號,括號內用。謝謝! – LamonteCristo 2011-01-13 18:03:20

0
ConfigurationManager.ConnectionStrings["Management_Report_Emailer.Properties.Settings.DWConnectionString"].ConnectionString; 
相關問題