Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i wanna change the app config file runtime in c#.net
4.0 version my code is:------------------
-----------------------------------
C#
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            int initialCount = ConfigurationManager.ConnectionStrings.Count;
            //string connStringName = txtConnName.Text;
            string serverName = txtserver.Text;
            string databaseName = txtdatabase.Text;
            string userId = txtUsername.Text;
            string password = txtPassword.Text;
            var connectionStringBuilder = new SqlConnectionStringBuilder
            {
                DataSource = serverName,
                InitialCatalog = databaseName,
                UserID = userId,
                Password = password
            };
            var csSetting = new ConnectionStringSettings(connectionStringBuilder.ConnectionString, "System.Data.SqlClient");
            //var csSetting = new ConnectionStringSettings(connStringName, connectionStringBuilder.ConnectionString, "System.Data.SqlClient");
            var csSection = config.ConnectionStrings;
            csSection.ConnectionStrings.Add(csSetting);
            config.Save(ConfigurationSaveMode.Modified, true);
            ConfigurationManager.RefreshSection("connectionString");
            int finalCount = ConfigurationManager.ConnectionStrings.Count;

-------------------------------------------------------------------------
this code working 3.5 but it is not working in 4.0
please help me its Urgent
...................Thank you
Posted
Updated 20-Jun-12 18:30pm
v2

Hi,

have you tried with google search ?

please check this[^] link. from the link you will get your answer.

hope this will help you,

thanks
-amit.
 
Share this answer
 
please look this Link[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900