modifying web.config in run time in asp.net?

  • Thread starter Thread starter mostafa goher
  • Start date Start date
M

mostafa goher

Guest
I am facing this problem for awhile now and it a pain in the butt,here what i want to do
i wan to make a page that takes sql server info and creates database in that server then add connection string in web.config in run time..i use this code to add the connection string in run time

//add to web.conf
Configuration webconf = WebConfigurationManager.OpenWebConfiguratio(Request.ApplicationPath);
//Clear connection strings
webconf.ConnectionStrings.ConnectionStrings.Clear();
//add
webconf.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSetting("ConnectionString", conString));
webconf.Save();

the connection string is saved in the web.confg, but when i try to access it it doesnt seem to find the connection string i just added..aperntly the .net framework loads the web.config in the application start to the memory and any modifications to the file doesnt affect the memory, i found this line on the internet to reload the web.config into memory but still doesnt work.
ConfigurationManager.RefreshSection("connectionStrings");
webconf.GetSection("connectionStrings");

well, anyone know how to solve this problem i will appreciate it.
thnx
 
Back
Top