how to add new connection string in web.config run time programatically in asp.net? -
i working on construction erp. when user adds new structure have create new database each structure.whether possible using script?
at same time creating new database each structure necessary create 1 additional connection string in web.config file
very first trying add new connection string in config file.for have written code.but gives me error.
string path = server.mappath(@"web.config"); 'or' string path = server.mappath("~/web.config"); var configuration = webconfigurationmanager.openwebconfiguration(path); var section = (connectionstringssection)configuration.getsection("connectionstrings"); section.connectionstrings.add(new connectionstringsettings(txtstructname.text, txtstructname.text, "system.data.sqlclient")); configuration.save();
error :the relative virtual path not allowed here.
help me solve problem.....
you shouldn't need specify web.config
.
just do
webconfigurationmanager.openwebconfiguration("~");
Comments
Post a Comment