我想從應用程序配置文件讀取連接字符串。從應用程序配置文件讀取連接字符串
但不斷收到一個錯誤:
The name ConfigurationManager does in exit in current context.
谷歌搜索的錯誤後,我加入ConfigurationManager中我的項目。但我仍然得到同樣的錯誤。
我的代碼:
string sqlConStr = ConfigurationManager.ConnectionStrings["AppConnectionString"].ToString();`
我的應用程序配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="AppConnectionString" connectionString="SERVER=1894; Database=db; UID=loss; PWD=where;encrypt=no;enlist=false" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
添加 「使用System.Configuration;」 – 2012-07-24 12:02:10
並確保您已添加對System.Configuration程序集的引用。 – 2012-07-24 12:03:39