Question

Is there an easy method to store a person's user settings in a sql 2000 database. Ideally all settings in one field so I don't keep having to edit the table every time I add a setting. I am thinking along the lines of serialize a settings class if anyone has an example.

The reason I don't want to use the built in .NET user settings stored in persistent storage is work uses super mandatory profiles so upon a users log off the settings are cleared which is a pain. I posted asking for any solutions to this previously but didn't get much of a response.

Was it helpful?

Solution

The VS designer keeps property settings in the ApplicationSettingsBase class. By default, these properties are serialized/deserialized into a per user XML file. You can override this behavior by using a custom SettingsProvider which is where you can add your database functionality. Just add the SettingsProvider attribute to the VS generated Settings class:

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

A good example of this is the RegistrySettingsProvider.

I answered another similar question the same way here.

OTHER TIPS

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

You could serialize into a database, or you could create a User settings table containing Name-Value pairs and keyed by UserId. The advantage of doing it this way is it's easier to query and update through RDMS tools.

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 build your API:

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

If you're already doing CRUD development (which I assume from the existence and availability of a database), then this should be trivially easy to implement.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top