【问题标题】:ConfigurationManager - How to use connection strings with .NET 3.5?ConfigurationManager - 如何在 .NET 3.5 中使用连接字符串?
【发布时间】:2011-03-22 10:54:08
【问题描述】:

我在这里看到一篇关于我想做的非常好的帖子,

.net 3.5: To read connectionstring from app.config?

它说要使用 ConfigurationManager 类。我无法引用 ConfigurationManager 类。

如果我查看我正在使用的 system.dll(即 v2.0.50727),则没有 ConfigurationManager 类。

我使用的是 VS 2008,我的项目设置为编译为 .NET 3.5。

如果我这样做,

string test = System.Configuration.ConfigurationManager.AppSettings["test"];

我收到消息“错误 182 名称空间“System.Configuration”中不存在类型或名称空间名称“ConfigurationManager”(您是否缺少程序集引用?)”

有什么想法吗?

【问题讨论】:

  • 是否添加了对 System.Configuration 的引用?
  • 对。我以为我有,但我在“System”dll 中引用了命名空间“System.Configuration”

标签: c# .net configuration connection-string


【解决方案1】:

ConfigurationManagerSystem.Configuration 命名空间的一部分。默认情况下,项目中不引用它,因此请添加对来自 GAC 的 if 的引用。

【讨论】:

  • 是的,如上所述,我在“System”dll 中引用了命名空间“System.Configuration”
【解决方案2】:

您已经引用了“system.configuration.dll”

在VS中右键点击参考文件夹,搜索这个dll

【讨论】:

    猜你喜欢
    • 2021-11-21
    • 2010-12-22
    • 2014-07-10
    • 2011-04-16
    • 2020-01-29
    • 1970-01-01
    • 2012-09-24
    • 2019-04-21
    相关资源
    最近更新 更多