473,320 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How can I access application settings?

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
Mar 9 '08 #1
2 1821
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" wrote:
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
Mar 10 '08 #2
Thanks Morten,

I'm sure one of those will work!

--
Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
"Morten Wennevik [C# MVP]" wrote:
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" wrote:
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
Mar 10 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: serge calderara | last post by:
dear all, I have problem accessing section group in my configuration application file. I got an error saying thta I can have only one section ???? here is my application configuration looks...
29
by: Patrick | last post by:
I have the following code, which regardless which works fine and logs to the EventViewer regardless of whether <processModel/> section of machine.config is set to username="SYSTEM" or "machine" ...
0
by: Yogesh Pancholi | last post by:
For some unexplained reason, I am suddenly unable to browse to a virtual directory on my laptop. I have a number of sample websites to which I could happliy browse up until last week. As of Monday,...
0
by: M | last post by:
I installed the Visual Basic .NET Resource Kit. When I click 'Visual Basic .NET Resource Kit' the page at 'http://localhost/VB.NETResourceKit/Welcome.aspx' show: Server Error in...
6
by: dbuchanan | last post by:
I have a Windows Forms application that accesses SQL Server 2k from a small local network. The application has been used for weeks on other systmes but a new install on a new machine retruns...
6
by: GS | last post by:
Hi, There is reference about accessing settings file in VB.NET but nothing about C#. How do I read settings in application settings file with C#? Thanks, G
2
by: Matthias Wohlmann | last post by:
Hi, I'm getting the following error when trying to start my application using Internet Explorer: "Server cannot access application directory D:\xxx. The directory does not exist or is not...
38
by: Oldie | last post by:
I have built an MS Access Application under MS Office XP (but I also own MS Office 2000). I have split the application in the pure database tables and all the queries, forms, reports and macro's. ...
1
by: maz01 | last post by:
Hello All, I am developing an application in visual basic 2005 that will run continuously in the background on a users workstation. This application will automatically transfer files from the...
4
by: RedHair | last post by:
I developed a Win form with VS.NET 2005 + .NET 2.0 in C# There are some application settings are "User" scope and stored in xxx.settings, I can access them via Settings class and changethem with...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.