Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

AppSettings - 500 pts

I have just upgraded to vb.net 2005

the following line says that it is no longer supported

      Return ConfigurationSettings.AppSettings("cn")
     
I changed it to

ConfigurationManager.AppSettings("cn") but it does not work
0
rocky050371
Asked:
rocky050371
1 Solution
 
rocky050371Author Commented:
The problem is I am accessing the config file for the main application from another layer. I had looked at the My object but it does not seem to have a settings option

0
 
Bob LearnedCommented:
Look at the ConfigurationManager class.

Bob
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
amyhxuCommented:
It's possible that the key you used in your code isn't right. Use the following code to list all the keys in AppSettings and find out the right key:

   Dim appSettings As NameValueCollection = ConfigurationManager.AppSettings
   Dim appSettingsEnum As IEnumerator = appSettings.Keys.GetEnumerator()
   
   ' Loop through the collection and display the appSettings key, value pairs.
   Dim i As Integer = 0
   While appSettingsEnum.MoveNext()
      Dim key As String = appSettings.Keys(i)
      Console.WriteLine("Name: {0} Value: {1}", key, appSettings(key))
      i += 1
   End While
0
 
Bob LearnedCommented:
ConfigurationManager has ConnectionStrings property also.

Bob
0
 
amyhxuCommented:
Here's one example I used in my code to get the ConnectionString:
ConfigurationManager.ConnectionStrings("AppName.My.MySettings.cnn").ConnectionString
0
 
amyhxuCommented:
If the one that you are looking for is not in AppSettings, then like Bob said, you could find out if it's in ConnectionStrings:
    Dim connectionStrings As ConnectionStringSettingsCollection = ConfigurationManager.ConnectionStrings
   
   ' Get the collection enumerator.
     Dim connectionStringsEnum As IEnumerator = connectionStrings.GetEnumerator()
   
   ' Loop through the collection and display the connectionStrings key, value pairs.
   Dim i As Integer = 0
   While connectionStringsEnum.MoveNext()
      Dim name As String = connectionStrings(i).Name
      Console.WriteLine("Name: {0} Value: {1}", name, connectionStrings(name))
      i += 1
   End While
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now