title: Right way to get username and password from connection string?
body: <p>I have a connection string like this:</p>
  
  <pre><code>"SERVER=localhost;DATABASE=tree;UID=root;PASSWORD=branch;Min Pool Size = 0;Max Pool Size=200"
  </code></pre>
  
  <p>How do I get the various database parameters out of it? I can get database name and server like this:</p>
  
  <pre><code>serverName = conObject.DataSource;
  dbName = conObject.Database;
  </code></pre>
  
  <p>I need the username and password as well similarly. No property is set on the MySqlConnection object.</p>
  
  <p>At present I do it like this: </p>
  
  <pre><code>public static void GetDatabaseParameters(string connectionString, out string serverName, out string dbName, out string userName, out string password)
  {
      Match m = Regex.Match(connectionString, "SERVER=(.*?);DATABASE=(.*?);UID=(.*?);PASSWORD=(.*?);.*");
  
      //serverName = m.Groups[1].Value;
      //dbName = m.Groups[2].Value;
      userName = m.Groups[3].Value;
      password = m.Groups[4].Value;
  }
  </code></pre>
  
  <p>Is there an accepted practice here?</p>