Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
<?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:

C#
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
Posted
Updated 5-Dec-16 2:27am
Comments
F-ES Sitecore 5-Dec-16 7:20am    
app.config is read-only, you're not supposed to change it. If you want different connection strings in different situations then put both strings in the config and have a "GetConnectionString" function that returns the relevant one and have your code call that function any time it wants a connection string.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900