The "connectionStrings" is the name of the section not the connection string name.
var configuration = WebConfigurationManager.OpenWebConfiguration("~");
var section = (ConnectionStringsSection)configuration.GetSection("connectionStrings");
section.ConnectionStrings["MyConnectionString"].ConnectionString = "Data Source=" + Server + ";Initial Catalog=" + Name + ";User ID=" + Username + ";Password=" + Password + ";Pooling=true;Min Pool Size=5;Max Pool Size=60;Connect Timeout=60";
configuration.Save();
I have copied solution from this
link