【问题标题】:Only one connectionstring from app.config is found仅找到 app.config 中的一个连接字符串
【发布时间】:2020-12-09 04:28:48
【问题描述】:

所以我的 WPF 项目中有带有三个连接字符串的 app.config:

<connectionStrings>
        <clear/>
        <add name="Production" connectionString="Data Source=LAPTOP-R1\SQLEXPRESS;Initial Catalog=VIP_R_PROD;Integrated Security=True;Pooling=False"/>
        <add name="Test" connectionString="Data Source=LAPTOP-R1\SQLEXPRESS;Initial Catalog=VIP_R_TEST;Integrated Security=True;Pooling=False"/>
        <add name="ProductionMySQL" connectionString="removed for security"/>
    </connectionStrings>

当我尝试以任何方式(索引或名称)访问第一个字符串下方的两个字符串时,它返回 null。 顶部字符串可以通过名称和索引访问。

使用时:

 MessageBox.Show(System.Configuration.ConfigurationManager.ConnectionStrings.Count.ToString());

它总是返回值“1”;

【问题讨论】:

  • 检查app.config是否以正确的名称复制到输出目录(your_application_name.exe.config)
  • 嘿@Steve,不是。它被存储为App.config。有什么想法吗?
  • 通常在构建过程中将文件app.config复制到项目本身的输出路径属性中定义的输出目录并重命名作为您的__application_name.exe.config_ 覆盖以前的版本。这是在每次构建时完成的。如果你没有看到 exe.config 文件或者它是一个过时的版本,那么有什么东西阻止了这个机制,可能是一个只读的 exe.config 文件或项目中注册的 app.config 文件的属性中的一些不同的东西结构体。 (我的默认设置是:Build Action=None,Copy to output directory=Do Not Copy)等等。
  • 您可以尝试创建一个新的 WinForms 应用程序并检查我在上一条评论中告诉您的区域是否存在差异
  • 我刚刚找到了一个名为“[appname].dll.config”的文件,但结果还是一样。

标签: c# connection-string app-config


【解决方案1】:

通过以下方式解决:

  • 将 Visual Studio 从 16.6.x 更新到 16.7.2
  • 从所有层中删除了所有 bin 和 obj 文件夹

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 2015-09-16
    • 2011-11-21
    • 2012-07-23
    相关资源
    最近更新 更多