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

2
  • 1
    Be aware that the connections strings section is read only. See this for details stackoverflow.com/questions/360024/… Commented Oct 7, 2013 at 12:46
  • i want to add new connection string.not change in existing string. Commented Oct 8, 2013 at 10:16

1 Answer 1

2

You shouldn't need to specify web.config.

Just do

WebConfigurationManager.OpenWebConfiguration("~");
Sign up to request clarification or add additional context in comments.

4 Comments

i have try for it but "An error occurred loading a configuration file: Failed to map the path '/'." is the error.....
@user1838502 is iis configured for that directory to be an application?
An error occurred loading a configuration file: Failed to map the path '/'.
@user1838502 make sure you have an application configured in iis.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.