无法使用 C# ConfigurationManager

发布于 2024-09-26 04:37:42 字数 528 浏览 7 评论 0原文

我有以下代码:

using System.Configuration;

namespace test
{
  public partial class MyService : ServiceBase
  {
    public  static ReadConnectionStrings()
    {                        
      ConnectionStringSettingsCollection connections =
          ConfigurationManager.ConnectionStrings;

但是,它无法识别 ConfigurationManager。我直接从 此处获取此代码

所以我显然错过了一些东西,但无法确定是什么。

I have the following code:

using System.Configuration;

namespace test
{
  public partial class MyService : ServiceBase
  {
    public  static ReadConnectionStrings()
    {                        
      ConnectionStringSettingsCollection connections =
          ConfigurationManager.ConnectionStrings;

However, it doesn’t recognise ConfigurationManager. I took this code directly from here

So I’m clearly missing something, but can’t identify what.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

伏妖词 2024-10-03 04:37:42

您有对 System.Configuration 的引用吗?默认情况下,它不会添加到 .NET 项目中。

Do you have a reference to System.Configuration? It's not added to .NET projects by default.

ぽ尐不点ル 2024-10-03 04:37:42

我也有同样的问题。

我花了一些时间才弄清楚添加引用并不是添加使用。我必须右键单击该项目并选择“添加引用”,然后在 .NET 选项卡中选择“System.Configuration”。

效果非常好!

I was having the same issue.

It took me a little while to figure out that adding the reference is not adding the using. I had to right-click the project and select Add Reference, then pick System.Configuration in the .NET tab.

Worked like a charm!

凝望流年 2024-10-03 04:37:42

确保您正在使用的实际项目引用了System.Configuration。我正在从事数据访问项目,而不是表示层项目。所以我有点困惑,因为我以为我有一个参考,但实际上数据项目缺少参考。

Ensure that the actual project you're working in has a reference to System.Configuration. I was working in a data access project, not the presentation layer's project. So I was getting a bit confused because I had thought I had a reference, but in reality the data project was missing the reference.

帅的被狗咬 2024-10-03 04:37:42

我必须下载程序集参考,然后添加到项目中,不确定其他人是否有这个问题

I had to download the assembly refernce then add to project not sure if others had this problem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文