C # save user settings in database

Is there an easy way to store user user settings in sql 2000 database. Ideally, all settings are in one field, so I don’t need to edit the table every time I add a setting. I am thinking about how to serialize a settings class if someone has an example.

The reason I don’t want to use the built-in .NET user settings stored in the persistent storage is the use of super mandatory profiles, so when users exit the settings mode they are cleared, which is a pain. I sent a request for any solutions about this earlier, but did not receive a response.

+4
source share
4 answers

The VS constructor saves property settings in the ApplicationSettingsBase class. By default, these properties are serialized / deserialized into an XML file for each user. You can override this behavior using the special SettingsProvider , in which you can add your database functionality. Just add the SettingsProvider attribute to the SettingsProvider generated VS class:

 [SettingsProvider(typeof(CustomSettingsProvider))] internal sealed partial class Settings { ... } 

A good example of this is RegistrySettingsProvider .

I answered another similar question in the same way here .

+4
source

you can easily serialize classes in C #: http://www.google.com/search?q=c%23+serializer . You can either store the XML in the varchar field, or if you want to use the binary serializer, you can save it as "Image" data, which is really just binary.

+1
source

You can serialize in the database or create a user settings table containing Name-Value pairs and a key for UserId. The advantage of this method is to facilitate querying and updating using RDMS tools.

+1
source

First you need your table.

 create table user_settings ( user_id nvarchar(256) not null, keyword nvarchar(64) not null, constraint PK_user_settings primary key (user_id, keyword), value nvarchar(max) not null ) 

Then you can create your API:

 public string GetUserSetting(string keyword, string defaultValue); public void SetUserSetting(string keyword, string value); 

If you are already developing CRUD (which I assume from the existence and availability of the database), then this should be trivially easy to implement.

0
source

Source: https://habr.com/ru/post/1277482/


All Articles