configurationManager在名称空间System.Configuration中不存在>> [

问题描述 投票:49回答:4
我已经使用以下命名空间将我的项目连接到sql服务器:

using System.Configuration;

也使用

string str=System.Configuration.ConfigurationSettings.AppSettings["myconnection"]; SqlConnection oconnection = new SqlConnection(str); oconnection.Open();

当我运行程序时,发生了一个错误并显示消息

'System.Configuration.ConfigurationSettings.AppSettings'是已过时。此方法已过时,已被替换'系统配置!System.Configuration.ConfigurationManager.AppSettings'

但是我在该命名空间中没有找到ConfigurationManager,对于oconnection.Open();,消息为

InvalidOperationException

未处理。

我该怎么办?

我已经使用以下命名空间将我的项目连接到sql服务器:using System.Configuration;并且还使用了字符串str = System.Configuration.ConfigurationSettings.AppSettings [“ ...

c# sql-server visual-studio-2005
4个回答
79
投票
转到参考,并添加对System.Configuration的参考

28
投票
如果解决方案中有多个项目,则必须为每个项目添加引用System.Configuration,以便ConfigurationManager可以在其中任何一个项目中工作。

16
投票
在您的项目中添加对:System.Configuration.dll的引用,然后将可以使用ConfigurationManager

0
投票
在最新版本的Visual Studio中,我必须通过NuGet包管理器添加System.Configuration.ConfigurationManager。
© www.soinside.com 2019 - 2024. All rights reserved.