Adding a Configuration File
Rather than hard coding connection information into the application, you can configure your application to load the information dynamically from a configuration file. To add a configuration file to your project do the following:
-
Add a reference to System.Configuration to your project.
-
Add the following using directive:
using System.Configuration;
-
Click Project –> Add New Item.
-
In the Add New Item dialog, click Application Configuration File. Enter a name for the file. Note that the name must have the following form: <Application Name>.config. For example, the name of the configuration file for the PhonebookObj application is PhonebookObj.exe.config.
-
In the property inspector, change the value of the configuration file's Copy to Output Directory build action to Copy always.