title: 2 or More ConnectionString on App.config MySQL VB.Net
body: <p>I got a code that can return the <strong>ConnectionString</strong> from the <code>App.Config</code> in my VB.Net project. My problem is whether I call <strong>online1</strong> or <strong>offline2</strong> the <strong>offline2 value is being called or more likely a default</strong>. </p>
  
  <p>I want to get a connection string base on <code>GetConnectionString([ConnectionString Name])</code></p>
  
  <pre><code>Public Shared Function GetConnectionString(ByVal strConnection As String) As String
      'Declare a string to hold the connection string
      Dim sReturn As New String(" ")
      Dim connections As ConnectionStringSettingsCollection = ConfigurationManager.ConnectionStrings
      'Check to see if they provided a connection string name
      If Not String.IsNullOrEmpty(strConnection) Then
          For Each connection As ConnectionStringSettings In connections
              If connection.Name = strConnection Then
                  'Retrieve the connection string fromt he app.config
                  sReturn = connection.ConnectionString
              Else
                  'Since they didnt provide the name of the connection string
                  'just grab the default on from app.config
                  sReturn = connection.ConnectionString
              End If
          Next
      End If
      Return sReturn
  End Function
  </code></pre>
  
  <p><strong>App.Config</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;startup&gt;
          &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
      &lt;/startup&gt;
    &lt;connectionStrings&gt;
      &lt;add name="online1" connectionString="SERVER=127.0.0.1; DATABASE=lto_db; UID=root; PASSWORD=;" providerName="MySql.Data.MySqlClient" /&gt;
      &lt;add name="offline2" connectionString="SERVER=localhost; DATABASE=lto_db; UID=root; PASSWORD=;" providerName="MySql.Data.MySqlClient" /&gt;
    &lt;/connectionStrings&gt;
  
  &lt;/configuration&gt;
  </code></pre>