Results 1 to 2 of 2

Thread: Need help with editing my vb.net app.config file

  1. #1

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Need help with editing my vb.net app.config file

    This is the app.config file of my vb.net project where my connection string to my database is stored.

    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
        </configSections>
        <connectionStrings>
            <add name="MySQL___Conn_Test.My.MySettings.wcConn" connectionString="server=localhost;User Id=root;password=123ssa1;database=wc"
                providerName="MySql.Data.MySqlClient" />
        </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>
    </configuration>
    Look at the part where it says:
    Code:
    <add name="MySQL___Conn_Test.My.MySettings.wcConn" connectionString="server=localhost;User Id=root;password=123ssa;database=wc"
                providerName="MySql.Data.MySqlClient" />
    Now this is my problem. I need to change this connection string to:
    Code:
    "server=192.168.0.24;User Id=root;password=123ssa;database=wc"
    The server is no longer local host, but set to the IP of the server.

    Here is where my problem comes in. This program will be used on 2 different servers, in other words the IP can't be hardcoded.

    Is it possible to edit the app.config file with coding? perhaps load the IP from a .ini file and then connect?

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Need help with editing my vb.net app.config file

    No, these sections are read-only.
    But you can store several connection strings in it and choose the appropriate one.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width