Results 1 to 5 of 5

Thread: [RESOLVED] [2005]Problem with my COnfiguration Settings

  1. #1

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Resolved [RESOLVED] [2005]Problem with my COnfiguration Settings

    Elow guys need help on why it occurs error in my vb.net2005 while on 2003 it does not have an error..Here is my code:


    Code:
      Dim aConfig As Configuration.ConfigurationSettings
    
        Dim strServerName As String = aConfig.AppSettings("ServerName")

    on my app.config file here is the code:


    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    	<appSettings>
    		<add key="ServerName" value="(local)"/>
    	</appSettings>
    </configuration>
    At my first child form it display no problem but when i call child of my first child form it displays "Access of shared members, constant member, enum member, or nested type through an instance; qualifying expression will not be evaluated". Why this error comes out guys? Need help on how to do it..Thanks in advance and have a nice day! God Bless..
    Last edited by shyguyjeff; May 4th, 2008 at 10:15 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005]Problem with my COnfiguration Settings

    Firstly, that's a warning, not an error.

    Secondly, looking at your code you should be able to see that you never actually create an instance of the ConfigurationSettings class and assign it to the aConfig variable, so how could you possibly access an instance member when you haven't created an instance? What the warning message is saying is that AppSettings is a Shared member, so the compiler is simply going to ignore your variable and access it via the class, which you should be doing in the first place, i.e.:
    vb.net Code:
    1. Dim strServerName As String = Configuration.ConfigurationSettings.AppSettings("ServerName")
    That said, the ConfigurationSettings class is obsolete in .NET 2.0. You should start using the ConfigurationManager class, which the compiler would also have told you.

    Note that the reason you didn't see this warning in VB.NET 2003 is not that your code wasn't wrong. It's just that the compiler fixed the problem silently rather than pointing out your mistake and letting you fix it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: [2005]Problem with my COnfiguration Settings

    hmmmmm....i see...but jm is there any way how to correct this warning?it doesn't run on my program and i couldn't connect to my configurationSettings. HOw can I use ConfigurationManager jm?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005]Problem with my COnfiguration Settings

    Well, I've already shown you exactly how to clear the warning from your existing code. The message says that it's a Shared member and Shared members are accessed via the type, not an instance of the type. As for using the ConfigurationManager class, have you made any attempt to read the documentation?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: [2005]Problem with my COnfiguration Settings

    Not yet jm but i will try to..Thanks again jm...Thanks for the info..Have a nice day to you...God Bless..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width