title: Protecting MySQL connection string
body: <p>I'm setting a mysql connection from C# application, but I'm just wondering if this code offers some kind of security against connection string hacks?, I just don't want to expose the connection credentials too much for them to be vulnerable. </p>
  
  <pre><code>protected MySqlConnection connection;
  protected string server;
  protected string database;
  protected string uid;
  protected string password;
  
  
  //Initialize values
  private void Initialize()
  {
      server = "localhost";
      database = "databaseName";
      uid = "username";
      password = "password";
      var connectionString = string.Empty;
      connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
  
      connection = new MySqlConnection(connectionString.ToString());
  }
  
  
  //open connection to database
  private bool OpenConnection()
  {
      try
      {
          connection.Open();
          return true;
      }
      catch (MySqlException ex)
      {
          //When handling errors, you can your application's response based on the error number.
          //The two most common error numbers when connecting are as follows:
          //0: Cannot connect to server.
          //1045: Invalid user name and/or password.
          switch (ex.Number)
          {
              case 0:
                  MessageBox.Show("Cannot connect to server.  Contact administrator");
                  break;
  
              case 1045:
                  MessageBox.Show("Invalid username/password, please try again");
                  break;
          }
          return false;
      }
  }
  </code></pre>
  
  <p>Thanks.</p>