[英]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;
部分不返回服務器應用程序配置的連接字符串,即 [目錄]。 誰能幫我解決這個問題?
ConnectionStringsSection().ConnectionStrings 提供配置中所有連接字符串的集合。
迭代以獲得所需的結果。
ConnectionStringSettingsCollection collection= config.ConnectionStringsSection().ConnectionStrings;
foreach(ConnectionStringSettings css in collection)
{
string output= css.Name;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.