views:

21

answers:

1

Hi everyone, 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 second 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

A: 

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.

Richard J Foster

related questions