0

I'm looking at a custom built .NET control (vb). It has a public string declared as:

Public Shared strConn As String = ConfigurationSettings.AppSettings("TheDB")

I'm trying to find out what "TheDB" is supposed to be exactly. I looked the web.config file of the website using this custom control, but there is no "TheDB" parameter anywhere. I also looked in the web server's machine.config file, and again, no "TheDB" parameters there either.

Help.

codingbiz
  • 26,179
  • 8
  • 59
  • 96
user1481183
  • 368
  • 2
  • 7
  • 19
  • TheDB is supposed to be the connection string that the control use in the database. It should be in web.config under . If its not there see if the appSettings has ConfigSource attribute to it such as if yes then look for a file that is specify in the configSource – atbebtg Aug 15 '12 at 20:59

3 Answers3

2

If it's missing, just add it:

 <appSettings>
     <add key="TheDB" value="somevalue" />
 </appSettings>

(assuming that ConfigurationSettings.AppSettings really corresponds to appSettings section of the web.config. This is not clear as normally you refer to standard sections of configuration files using builtin ConfigurationManager class)

Wiktor Zychla
  • 47,367
  • 6
  • 74
  • 106
  • That's a built-in class too. It's just depreciated. – Phillip Schmidt Aug 15 '12 at 21:01
  • True. If you don't define the key in the .config file, the app will default to the value that was configured at compile time. – tgolisch Aug 15 '12 at 21:03
  • @PhillipSchmidt: I've checked it out and indeed, thanks for reminding that. – Wiktor Zychla Aug 15 '12 at 21:34
  • @WiktorZychla I only know that because the company I used to work for seems to write code as if it were 1995. ConfigurationSettings, tables for layout, etc. – Phillip Schmidt Aug 15 '12 at 21:36
  • @PhillipSchmidt: I use .NET since 2002 and I must have been using that class. However, I am so used to `ConfigurationManager` now that I have completely forgotten `ConfigurationSettings` (so that I thought it could be a custom class). – Wiktor Zychla Aug 15 '12 at 21:41
2

Look in your web.config. Somewhere in there is a section called "AppSettings", where there should be some elements that look like this:

<add key="TheDB" value="something" />

One of them will be yours. Or possibly somebody took it out. More than likely, though, it's the connection string to your database.

Phillip Schmidt
  • 8,805
  • 3
  • 43
  • 67
0

web.config is hierarchical. Each web.config supplies configuration information to the directory in which it is located and to the entire directory hierarchy beneath it.

http://msdn.microsoft.com/en-us/library/ms178685.aspx

Been that way since .Net v1.1. When you look for a configuration value or section, the .Net configuration system looks in the lowest level web.config. If the desired value is not found, it runs up the directory tree until it finds it.

You need to run up the directory hierarchy (and yes, that includes virtual directories mounted in IIS as well) until you find the web.config file containing the desired appsetting value. There is also the IIS ApplicationHost.config as well, located at

%windir%\system32\inetsrv\config
Nicholas Carey
  • 71,308
  • 16
  • 93
  • 135