Question

I am attempting to use this code:

 String MainDB = ConfigurationManager.AppSettings["MainDB"];
 MessageBox.Show(MainDB);
 String MailInfo = ConfigurationManager.AppSettings["MailInfo"];
 MessageBox.Show(MailInfo);
 String HousingIndexLocation = ConfigurationManager.AppSettings["HousingIndex"];
 MessageBox.Show(HousingIndexLocation);

to access values generated by this screen:

enter image description here

Everytime the values are returned null.

what am I missing in my implementation of these settings?

Was it helpful?

Solution

Try

String MainDB = Properties.Settings.Default.MainDB;
MessageBox.Show(MainDB);
String MailInfo = Properties.Settings.Default.MailInfo;
MessageBox.Show(MailInfo);
String HousingIndexLocation = Properties.Settings.Default.HousingIndex;
MessageBox.Show(HousingIndexLocation);

OTHER TIPS

You're getting an error because ConfigurationManager is not the proper way to access properties stored in those files. Take a look at:

Using Settings in C#

Long story short, you access the settings in the Settings file using the Properties namespace:

Properties.Settings.Default.MainDB;
// And so on...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top