How can I access application settings?

  • Thread starter Thread starter Phil Johnson
  • Start date Start date
P

Phil Johnson

Hi, I have right clicked my project in VS2008 and added a DB Connection
application setting.

How do I access these settings from my code?

I know this must be pretty simple, but I cannot see how to do it.

--
Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
 
Hi Phil,

If you added an appSetting called DBConnection

string value = ConfigurationManager.AppSettings["DBConnection"];

If you added a connectionString called DBConnection

string value =
ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;

If you added a Setting called DBConnection

string value = Properties.Settings.Default.DBConnection;

or

string value =
ConfigurationManager.ConnectionStrings["MyNameSpace.Properties.Settings.DBConnection"].ConnectionString
 
Thanks Morten,

I'm sure one of those will work!

--
Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com


Morten Wennevik said:
Hi Phil,

If you added an appSetting called DBConnection

string value = ConfigurationManager.AppSettings["DBConnection"];

If you added a connectionString called DBConnection

string value =
ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;

If you added a Setting called DBConnection

string value = Properties.Settings.Default.DBConnection;

or

string value =
ConfigurationManager.ConnectionStrings["MyNameSpace.Properties.Settings.DBConnection"].ConnectionString


--
Happy Coding!
Morten Wennevik [C# MVP]


Phil Johnson said:
Hi, I have right clicked my project in VS2008 and added a DB Connection
application setting.

How do I access these settings from my code?

I know this must be pretty simple, but I cannot see how to do it.

--
Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
 
Back
Top