Translate

> > c# change App.config files Connection String

c# change App.config files Connection String

Posted on Sunday, May 1, 2011 | No Comments

using System.Configuration;

string newConnectionString1 = "Data Source=" + txtServer.Text + ";Initial Catalog=Garments;Persist Security Info=True;User ID=" + txtLogin.Text +";Password="+ txtPass.Text;


 string newConnectionString2 = "Data Source=" + txtServer.Text + ";Initial Catalog=Garments;Persist Security Info=True;User ID=" + txtLogin.Text + ";Password=" + txtPass.Text;
           

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            config.ConnectionStrings.ConnectionStrings["Germens_production.Properties.Settings.GermensConnectionString"].ConnectionString = newConnectionString1;
            config.ConnectionStrings.ConnectionStrings["Germens_production.Properties.Settings.GarmentsConnectionString"].ConnectionString = newConnectionString2;

config.Save(ConfigurationSaveMode.Modified, true);
            ConfigurationManager.RefreshSection(config.ConnectionStrings.SectionInformation.SectionName);

Leave a Reply

Powered by Blogger.