Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

System.Configuration.ConfigurationSettings.AppSettings("PubsString")

Posted on 2004-04-07
8
Medium Priority
?
839 Views
Last Modified: 2012-06-21
Hello,
I am proficient in ASP and Cold Fusion, but I am very new to .net and am doing the quickstart tutorials on www.asp.net (can anyone recommend a better tutorial?) and I am now doing intro8.aspx.

I notice that the example uses:
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("PubsString"))

I can connect to a DB by putting in a connection string, but keeping the connection string in one place is much better, I presume that is what this line does?
How do I set this property?

I am using webmatrix.

Thanks
0
Comment
Question by:hanneman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 4

Expert Comment

by:Jarodtweiss
ID: 10773632
The line System.Configuration.ConfigurationSettings.AppSettings("PubsString") means that you have stored somehting in the config file or your application (web.config for a web project or app.config for a windows app).
To add such a file, right lcik on your project and Add New Item --> Application Configuration file.

Then you need to add the tags <appSettings> between the <configuration> one and add your key !

<configuration>
  <appSettings file="Server_FO.config">
    <add key="PubsString" value="You connection String here"></add>
0
 
LVL 2

Accepted Solution

by:
eric_duncan earned 500 total points
ID: 10773634
All .Net applications - windows, console, and web alike, allow configuration information to be stored in a configuration file for ease of use. That being said, to add the connection string information to your web applications, add the following section to your web.config file (which should be located in the root of the web application):

<appSettings>
       <add key="PubsString" value="the connection string"/>
</appSettings>

Check out the following links for more information:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/gngrfappsettingselement.asp
http://www.extremeexperts.com/Net/FAQ/StoringConnectionString.aspx
0
 
LVL 2

Expert Comment

by:eric_duncan
ID: 10773642
Oops ... looks like we were answering at the same time!!
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 4

Expert Comment

by:Jarodtweiss
ID: 10773645
:-)
Two seconds quicker ;-)
0
 
LVL 2

Expert Comment

by:eric_duncan
ID: 10773658
Jarodtweiss, will the entries listed in the web.config under the <appSettings> node be processed if you have specified an external file for storage? I didn't think that they would, but I could be wrong.
0
 
LVL 4

Expert Comment

by:Jarodtweiss
ID: 10773680
Yeah they will !
I am using :
<configuration>
  <appSettings file="myFile.xml">

In that case, .NET will :
1. Check in myFile.xml if the given key exist.
    If it is the case, you get that value
2. If the key doesn't exist, it will check in the "standard file" if it exists
    If it is the case, you get that value
3. Otherwise, you get String.Empty

For Hanneman, in that case, myFile.xml must have the following structure :
<?xml version="1.0" encoding="utf-8" ?>
  <appSettings>
  <appsettings>
0
 
LVL 4

Expert Comment

by:Jarodtweiss
ID: 10773682
So the "alternative file" will "override" the key of the main file
0
 
LVL 4

Author Comment

by:hanneman
ID: 10773716
hey, i thought there used to be an option for assisted answers?
I was going to split the points because I used both your answers.

I used eric's code, and jarod gave me the method for adding a web.config file (i am that ignorant that i need that kind of info)

Thanks both of you.
-h
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question