Click here to Skip to main content
Sign Up to vote bad
good
See more: C#ASP.NET
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.
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 14 Nov '12 - 23:43
Edited 15 Nov '12 - 0:52
Tadit Dash22.5K

Comments
Anele Ngqandu - 15 Nov '12 - 6:04
Show us how do you connect or call your connection string from the code behind file
Narra sreenu - 15 Nov '12 - 6:36
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();

2 solutions

  Permalink  
Please go through Write Modify Web.Config Programmatically At Run Time[^] and try to implement the codes given there.
 
It may help.
 
Thanks...
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 233
1 Sergey Alexandrovich Kryukov 208
2 Rohan Leuva 195
3 Abhinav S 168
4 Mahesh Bailwal 165
0 Sergey Alexandrovich Kryukov 8,474
1 OriginalGriff 6,714
2 CPallini 3,603
3 Rohan Leuva 2,853
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid