Retrieving connection string from app.config
-
I am building a C# window app and am trying to 1. Create a DataAccess class which retrievs the connection string from app.config and then 2. call the DataAccess from a form load. I have successfully created the DataAccess.cs class but am having difficulties creating the retrieval of the app.config connection string. Does anyone have suggestions or a GOOD site with a simple C# example of how to do this.
-
I am building a C# window app and am trying to 1. Create a DataAccess class which retrievs the connection string from app.config and then 2. call the DataAccess from a form load. I have successfully created the DataAccess.cs class but am having difficulties creating the retrieval of the app.config connection string. Does anyone have suggestions or a GOOD site with a simple C# example of how to do this.
At the top of your file put:
using System.Configuration;
When you want to retrieve the setting use:string connString = ConfigurationSettings.AppSettings["MyConnectionStringSetting"];
(Change "MyConnectionStringSetting" to the name of the setting in the app.config[^] file)
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog