在数据库C#中存储的用户设置

问题描述:

有一个简单的方法来存储在SQL 2000数据库中一个人的用户设置。理想的情况是在某一领域的所有设置,所以我不保持有我每次添加一个设置,编辑表格。我沿着如果任何人有一个例子序列化设置类的思路思考。

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.

我不希望使用内置的存储在持久性存储.NET用户设置的原因是工作使用超级强制配置文件,以便在一个用户注销的设置将被清除这是一种痛苦。我张贴要求到此previously任何解决方案,但并没有得到太多的响应。

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.

该VS设计保持了的 ApplicationSettingsBase 类。默认情况下,这些属性是序列化/反序列化到每个用户的XML文件。您可以通过使用自定义 SettingsProvider 覆盖此行为,在这里你可以添加你的数据库的功能。只需添加 SettingsProvider 属性到VS生成设置类:

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 { 
   ...
}

这方面的一个很好的例子就是 RegistrySettingsProvider

我回答了另一个类似的问题同样的方式here.

I answered another similar question the same way here.