我想从应用程序配置文件读取连接字符串。从应用程序配置文件读取连接字符串
但不断收到一个错误:
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