我創建了一個控制檯應用程序項目,然後將新的App.conf文件添加到我的項目中。在我的配置文件,我抄,我已經通過如下增加實體框架創建的連接字符串:在控制檯應用程序中獲取連接字符串
<connectionStrings>
<add name="DBEntities" connectionString="metadata=res://*/DBModel.csdl|res://*/DBModel.ssdl|res://*/DBModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=MY-LAPTOP;Initial Catalog=TestDB;User ID=test;Password=123123;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
在我想用ConfigurationManager中類保持連接字符串,但始終鼓舞了我錯誤的Program.cs。
String connString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
請建議我解決方案。提前致謝。
我已經固定我problems.In我的解決方案有很多項目。基本上,在部署項目上,我將連接字符串部分複製到web.conf或app.conf,然後我可以讀取連接字符串。非常感謝您的回覆。 – nvtthang 2011-05-18 17:21:26