Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.ConnectionStrings.ConnectionStrings["MyConnectionString",String.Format("DataSource={0};")].ConnectionString=textBox1.Text; config.Save(ConfigurationSaveMode.Modified, true); ConfigurationManager.RefreshSection("connectionStrings");
I have problems with the second line. It seems I can not syntax correctly. As you can see, I only want to update the value of the DataSource. For example, if the current value is Data Source = PC001 \ SQL2008EXPRESS , I want it to be updated so that the client is included in textBox1.
EDIT: ConnectionString Example
<add name="ERPDatabaseTables" connectionString="metadata=res://*/ERPTables.csdl|res://*/ERPTables.ssdl|res://*/ERPTables.msl;provider=System.Data.SqlClient;provider connection string="Data Source=PC001\SQL2008EXPRESS;Initial Catalog=MyDatabase.mdf;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"/>
so you want to update only Data Source = PC001 \ SQL2008EXPRESS
source share