Results 1 to 6 of 6

Thread: [RESOLVED] A bit confused about Application Settings

  1. #1

    Thread Starter
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Resolved [RESOLVED] A bit confused about Application Settings

    Here is my specific need. Please help me understand and properly implement.

    I have a connection string for my database, it is automatically stored in the app.exe.config file with password and all.

    First thing is I would like to have that encrypted in some way so it is not visible, but it needs to be there in order to be able to manage the data in the designer.

    Second, how can I change that setting so that all users accessing from any computer get the change? Application settings are read only and user settings are, well, user settings so they apply only to the current.

    Thank you
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

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

    Re: A bit confused about Application Settings

    Application-scoped settings are read-only via My.Settings but that doesn't mean that you can't edit the config file. The issue is that you need to be logged in as an admin user in order to do so. Follow the CodeBank link in my signature and check out my thread on Protected Configuration for an example of both the things you want, i.e. encrypting the connection string and editing it. I can't recall whether I have but, if not, you can search the web for how to determine whether the current user is an admin and thus whether to let them edit.
    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
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: A bit confused about Application Settings

    Thank you, I was starting to feel like nobody would answer. It is no problem about the admin issue, since I do not need for every other user to change the parameters. I just need to be able to do it by the admin himself and then all users get the settings. Like if the server changes, we only need to change the connection string once, that was the whole point. I do not want each user to have to change it for their account.
    So, getting back on the issue, do I just edit the file like a normal XML? On MSDN documentation I read that there would be an app.exe.config and a user.config file, but I did not find the user one, but all the user settings were on the same app.exe.config file. Did I read or do something wrong?
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  4. #4

    Thread Starter
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: A bit confused about Application Settings

    Thank you Jmc, your post in the codebank was exactly what I was looking for, no more, no less. It addresses both my issues right on target. The only thing that I found is that you say that it throws an exception for some special situation. I could not make it fail... LOL.
    Kudos!
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: A bit confused about Application Settings

    The user config file is tucked away in their profile... once they change...


    there's several config files and htey are layered on to each other... and they have a specific loading order...

    First up is the Machine.Config file ... Not sure where this is stored (it's been a while since I've needed access to it) and is at the top level.
    Since I'm assuming this is a desktop app, I'm going to go down that route (ASP.NET apps at this point split and follow a different loading pattern)...
    Which means the app.config file then gets loaded... it OVERLAYS the Machine.Config file... so if they share any configurations, the Application one takes precedence...
    Next comes the User.Config ... like the previous, it also overlays what was previously loaded... so if it shares and configuration with the previous two, it takes precedence.

    So when you look in the application.config file, you'll find the same settings found in the User.Config file... these are the DEFAULT settings/values for them. When a user does something to change them, they are then saved in the user's config file.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: A bit confused about Application Settings

    Thank you techgnome, I figured that out and it answers one of my questions. It is just for information as it does not affect what I was trying to do but good information anyway.
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

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