Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
when adding a new connection string to the web.config file from code file. the following error is occurred. how to rectify this problem.Code is as follows.
C#
System.Configuration.Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
        //        AppSettingsSection appSettingsSection = (AppSettingsSection)configuration.GetSection("connectionStrings");
        //        if (appSettingsSection != null)
        //        {
        //            appSettingsSection.ConnectionStrings[key].ConnectionString = value; = "Data Source=" + DbServerName+ ";Initial Catalog=" + DbName+ ";User ID=" + DbUserName + ";Pwd=" +DbUserPass+ "";
        //            configuration.Save();
Posted
v3
Comments
Anele Ngqandu 15-Nov-12 6:04am    
Show us how do you connect or call your connection string from the code behind file
Narra sreenu 15-Nov-12 6:36am    
System.Configuration.Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
// AppSettingsSection appSettingsSection = (AppSettingsSection)configuration.GetSection("connectionStrings");
// if (appSettingsSection != null)
// {
// appSettingsSection.ConnectionStrings[key].ConnectionString = value; = "Data Source=" + DbServerName+ ";Initial Catalog=" + DbName+ ";User ID=" + DbUserName + ";Pwd=" +DbUserPass+ "";
// configuration.Save();

 
Share this answer
 
v2
Please go through Write Modify Web.Config Programmatically At Run Time[^] and try to implement the codes given there.

It may help.

Thanks...
 
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