app.config部分帮助 [英] app.config Section help

查看:67
本文介绍了app.config部分帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



希望有人可以放光,



我需要添加一个整个部分到我的配置文件。这是我需要添加到我的app.config文件的是:



Hi Guys,

Hope someone can shed some light,

I need to add a whole section to my config file. This is what i need to add to my app.config file is:

<connectionStrings>
        <add name="Database" connectionString="Server=BACKSERVER;database=Fingerscan;connection timeout=30;User Id=sysdba;Password=masterkey"
            providerName="System.Data.SqlClient" />
</connectionStrings>





我需要在运行时执行此操作。我需要添加带有标签的整个connectionStrings部分< connectionstring>



这可能吗?



在此先感谢。



I need to do this at runtime. I need to add the entire connectionStrings section with tags <connectionstring>

Is this possible?

Thanks in advance.

推荐答案

获得解决方案



Got the solution

try
           {
               var cfg = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
               var setting = new ConnectionStringSettings();

               setting.ConnectionString = "Server=BACKSERVER;database=Database;connection timeout=30;User Id=sysdba;Password=masterkey";
               setting.Name = "DatabaseName";
               cfg.ConnectionStrings.ConnectionStrings.Add(setting);
               cfg.Save();
           }
           catch (Exception ex)
           {
               Console.WriteLine(ex.ToString());
           }


这篇关于app.config部分帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆