I am using the user.application both programmatically and by the project.properties.settings feature.
While user settings are quite simple, the application settings are more tricky, as they can not be directly set programatically (write protetced), and when starting the application, the application settings are automatically loaded.
It it unclear (to me) at what point in the startup process this happnes.
It is unclear how and when I am supposed to instantiate the objects that are then set or modified by the automatic setting.
Can someone who has good understanding of the application setting help me get better understanding?
(Could not find answer to my question on the web)
Thanks
Samtal
VulpesPosted Jun 9, 2014, 8:46 AM
SamPosted Jun 12, 2014, 12:28 PM
The funny thing is that I can easily save a dataset as user setting (as xml). Works like charm.
So, why not App setting?
I can find a workaround to preserve my data, but it will necessitate additional user steps (I anyhow use Excel file as the dataset source).
I did not yet give up, and will try harder at later time. Will let you know. samtal
VulpesPosted Jun 12, 2014, 12:19 PM
Although creating a strongly typed DataSet (DataSet1) and associating a DataTable with it was no problem at design time, I couldn't then find any obvious way to use this as a type for an application setting - only the generic System.Data.DataSet could be used.
If I then tried to add something like: new DataSet1() in the value column I was informed that it can't be converted to System.Data.DataSet even though it's derived from it!
Is it really necessary to use a DataSet as the actual setting. Could you just store a connection string and a query which enables you to generate it at runtime instead?
SamPosted Jun 11, 2014, 10:18 AM
Using VS2010 Express, Win7-64. In my application I Have several Application settings. Most (mixed types) are User Settings, one is Application Setting (a DataSet).
I use the built-in Settings table where the one setting scope is set as Application, while the others scope is User. The User settings are all saved and retrieved OK, and can also be seen in the XML file.
(string userConfig = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;)
Problem: While the User settings are saved OK, the one Application Setting is not saved and is not present in the relevant config file.
(string appConfig = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None).FilePath;).
In the Settings.Design file we can see the Application Setting as read-only item (get only), which is OK, but no data is saved, and no data is found, (except a null DataSet). There is similar DataSet in the User settings that is saved OK, and can be loaded. To save the settings, I run: Properties.Settings.Default.Upgrade(); Properties.Settings.Default.Save();
Thanks
VulpesPosted Jun 10, 2014, 5:54 PM
If you still have VS 2008, it might be an idea to add a DataSet setting again to a new project, check you can retrieve it OK and then try and reproduce the same steps in your VS 2010 project, just in case you missed something the first time.
SamPosted Jun 10, 2014, 3:15 PM
While it is all true, yet, it is not clear to me how a setting is treated at startup, in particular an application setting.
I can easily define, preserve and retrieve user settings, be it strings or datasets.
I do it with the help of the Settings.setting class and associated table, where I set the scope to User, and then manipulate programatically as required (both saving and retrieving).
When I set the scope to Application, I can see the specific setting in the Settings.Designer as read-only (Get only), but I can not get it back after startup (example: this.fareDataSet = Properties.Settings.Default.fareDataSet; will returns a null DataSet.
I made sure I have the full dataset object upon closing and saving, but it is lost somewhere when I close the form or reopen it.
In previous versions of VS2008 I remember I could save the application scope, and I could even see the detailed html dataset file, which I can not locate with my current VS2010.
Any idea or advise?
Thanks.