-1

I am working on construction ERP. When user adds new structure i have to create new database for each structure.Whether it is possible using script?

at the same time as i am creating new database for each structure then it is necessary to create one additional connection string in web.config file

very first i am trying to add new connection string in config file.for that i have written some code.but it 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 is :The relative virtual path is not allowed here.

help me to solve this problem.....

user1838502
  • 37
  • 1
  • 1
  • 11
  • 1
    Be aware that the connections strings section is read only. See this for details http://stackoverflow.com/questions/360024/how-do-i-set-a-connection-string-config-programatically-in-net – Mike Goodwin Oct 07 '13 at 12:46
  • i want to add new connection string.not change in existing string. – user1838502 Oct 08 '13 at 10:16

1 Answers1

2

You shouldn't need to specify web.config.

Just do

WebConfigurationManager.OpenWebConfiguration("~");
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445