title: ConfigurationManager.ConnectionStrings.Add
body: <p>My mind is boggled here - There is an Add method on ConfigurationManager.ConnectionStrings
  However if I use it, it throws a "Read Only" error message. My research on the issue has shown that we cannot add connections strings programatically at runtime to the app.config. There is a workaround for this using reflection to set the ReadOnly flag to false</p>
  
  <p>Here is the example with reflection: </p>
  
  <pre><code> public static void AddConnectionString(SqlConnectionStringBuilder connectionString,string Name)
      {
          try
          {
              typeof(ConfigurationElementCollection).GetField("bReadOnly", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(ConfigurationManager.ConnectionStrings, false);
              ConfigurationManager.ConnectionStrings.Add(new ConnectionStringSettings(Name, connectionString.ConnectionString));
              EventLogger.LogEvent("Added ConnectionString",1);
              ProtectConnectionStrings();
  
          }
          catch (Exception ex)
          {
              EventLogger.LogError(ex.Message,(int)EventLogger.Events.GeneralException);
          }
  
      }
  </code></pre>
  
  <p>But none of this makes sense to me. I want to store conStrs in the app.config so I can encrypt them. I need users to be able to add them to the app.config at runtime. What is the standard way of accomplishing this?</p>