Can we change the settings of the Windows applications app.config?
I have two app.config's in my application where i have written two connectionstrings in one config file and another two in other config file .Now in .cs file i have written this
string Connect = ConfigurationManager.ConnectionStrings["con1"].ConnectionString.ToString();
string Connect = ConfigurationManager.ConnectionStrings["con3"].ConnectionString.ToString();
Now first line gives the connectionstring from app.config.But for the sec开发者_Go百科ond line am getting an error that "object reference not set to an instance"
Can any one tell me how to use the connection from different app.config's
Per Microsoft's documentation for the ConfigurationManager class, the ConnectionStrings property operates on the current application's default configuration file.
I believe that what you probably want to do is use the OpenExeConfiguration method to read the second app.config file then use the returned Configuration class instead of the static ConfigurationManager.
精彩评论