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
rocky050371Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.