|
-
Mar 17th, 2016, 09:56 AM
#1
[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
-
Mar 17th, 2016, 10:58 PM
#2
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.
-
Mar 18th, 2016, 09:15 AM
#3
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
-
Mar 18th, 2016, 12:31 PM
#4
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
-
Mar 18th, 2016, 12:37 PM
#5
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
-
Mar 18th, 2016, 12:41 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|