如何更新app.config [英] How do I update app.config

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

问题描述

大家好



我有一个.net应用程序



我需要一些帮助更新应用程序。配置文件 - connectionstring



它有3个连接字符串条目我想更新1



我有找到了代码,但这不会更新任何内容。



请指出正确的方向



下面app.config:





Hi All

I have a .net application

I need some help updating app.config file - connectionstring

it has 3 connectionstring entries of which i like to update 1

I have found code but this does not update anything.

please point me in the right direction

Below the app.config:


<?xml version="1.0"?>
<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
        <add name="FlexiSchool.My.MySettings.AbacusSchool_beConnectionString"

            connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Hss\data\Azura\Flexischool\DATA_be.mdb"

            providerName="System.Data.OleDb" />
        <add name="FlexiSchool.My.MySettings.SI_DBConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Hss\data\Azura\Flexischool\SI_DB.accdb"

            providerName="System.Data.OleDb" />
        <add name="FlexiSchool.My.MySettings.AdminSettingsConnectionString"

            connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Hss\data\Azura\Flexischool\AdminSettings.mdb;Persist Security Info=True;Jet OLEDB:Database Password=ilze10koen"

            providerName="System.Data.OleDb" />
    </connectionStrings>
    <system.diagnostics>
        <sources>
            <!-- This section defines the logging configuration for My.Application.Log -->
            <source name="DefaultSource" switchName="DefaultSwitch">
                <listeners>
                    <add name="FileLog"/>
                    <!-- Uncomment the below section to write to the Application Event Log -->
                    <!--<add name="EventLog"/>-->
                </listeners>
            </source>
        </sources>
        <switches>
            <add name="DefaultSwitch" value="Information"/>
        </switches>
        <sharedListeners>
            <add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter"/>
            <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
            <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
        </sharedListeners>
    </system.diagnostics>
	<startup>
		
	<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>

</configuration>





我尝试过:



在代码片段下方:





What I have tried:

below the code snippet:

Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

   Dim mySection As ConnectionStringsSection = DirectCast(config.GetSection("FlexiSchool.My.MySettings.AbacusSchool_beConnectionString"), ConnectionStringsSection)
   config.ConnectionStrings.ConnectionStrings("FlexiSchool.My.MySettings.AbacusSchool_beConnectionString").ConnectionString = DataPath.Text & "DATA_BE.mdb"

   Try
       config.Save(ConfigurationSaveMode.Full)
   Catch ex As Exception
       ex.Message.ToString()
   End Try


   'ConfigurationManager.RefreshSection("connectionStrings")
   Try
       ConfigurationManager.RefreshSection("connectionStrings")
   Catch ex As Exception
       ex.Message.ToString()
   End Try

推荐答案

c# - 动态更改app.config文件中的值 - Stack Overflow [ ^ ]



http://stackoverflow.com/questions/11149556/app-config-change-value [ ^ ]


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

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