繁体   English   中英

如何从 C# 中的服务器位置获取 app.config 值

[英]How to app.config value from server location in c#

我想在程序中读/写(和使用)应用程序的配置文件

服务器的 app.config

  <configSections>
   <section />
  </configSections>
    <connectionStrings>
  <add name="catalogue" connectionString="Data Source=abc\_SQLSERVER;Initial 
  Catalog=Catalogue;Integrated Security=False;Persist Security Info=False; user ID=sa;password=****;" 
    providerName="System.Data.SqlClient"/>
      </connectionStrings>
        <dataConfiguration defaultDatabase="Catalogue"/>
     <startup>

  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
 <appSettings>


     </appSettings>
    </configuration>

我想使用 app.config 文件,该文件位于其他服务器位置 '\\abc\\BaseSoftwares\\hanah\\abc.exe.config' 上的以下位置,而不是本地配置。 使用配置管理器。 OpenExe配置

    string pathString = System.IO.Path.Combine(CentralizedPath, "abc.exe.config"); 
    Configuration config = ConfigurationManager.OpenExeConfiguration(pathString);

    ConnectionStringsSection section = config.GetSection("connectionStrings") as 
         ConnectionStringsSection;

部分不返回服务器应用程序配置的连接字符串,即 [目录]。 谁能帮我解决这个问题?

  1. ConnectionStringsSection().ConnectionStrings 提供配置中所有连接字符串的集合。

  2. 迭代以获得所需的结果。

ConnectionStringSettingsCollection collection= config.ConnectionStringsSection().ConnectionStrings;

foreach(ConnectionStringSettings css in collection)
{
   string output= css.Name;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM