如何持久化/保存程序信息
我编写了一个在启动时自动运行的提醒程序。我想知道除了 SQL-Server 之外是否还有其他方法来存储事件、日期和时间数据。我不想使用 SQL-Server 来完成这项工作,因为我认为 SQL-Server 对于这项简单的任务来说非常大。我认为我可以使用文件来存储数据。您对此有何看法?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
存储信息的一些常见方式:
注册表项对于用户操作来说更安全。另一方面,文件可以轻松删除。
您始终可以选择加密您的信息。
附带说明一下,您还可以使用 PostSharp 声明要存储在注册表中的变量。代码变成这样:
如果您需要的话,我可以稍后提供代码......当我再次回家时。
Some common ways to store information:
Registry entries are more safe regarding user actions. On the other hand, files can be easily deleted.
You always have the option, to encrypt your information.
As a side note, you can also use PostSharp to declare variables to be stored in your registry. The code becomes something like this:
I can provide code later if you need it... when I'm home again.
对于要保留的部分位置
从此文档(管理用户数据部署指南,下载):
因此,我建议使用 AppData\Roaming 并保存到文件,因为我认为“提醒应用程序”是特定于用户的。例如,域用户会认为这是有价值的(同步到服务器)。
Local
和LocalLow
(后者用于低完整性模式,适用于权限较低的应用程序)更适合某些可以计算的机器/安装特定数据 -苍蝇。Registry
似乎非常适合一些少量的密钥,但似乎不是此类用途的最佳选择。还有另一个选项 -
IsolatedStorage
,当提到的选项不适用时(例如使用 ClickOnce 部署时),应使用该选项。对于如何将数据保存到文件的部分......好吧,选择您最喜欢的。如果您想要更多的控制和功能,您可以使用 SQLite 数据库,它真的很轻量级;如果您认为使用 SQLite 是一种过度杀伤力,则可以仅使用 XML 序列化到文件。或者任何其他可行的选择。
For the part where to persist
From this document (Managing User Data Deployment Guide, download):
So, I suggest using
AppData\Roaming
and persisting to a file since I consider a 'reminder app' to be user specific. And domain users for example would consider that valuable (syncing to server).Local
andLocalLow
(the latter is used for low integrity mode, for applications with reduced privileges) would be more appropriate for some machine/installation specific data which can be calculated on-the-fly.Registry
seems great for some low amount of keys, but doesn't seem to be the best option for such use.There is another option -
IsolatedStorage
, which should be used when mentioned options are not applicable, like when using ClickOnce deployments.For the part how to persist your data to a file ... well, pick your favorite. You could use SQLite database which comes really lightweigt if you want more control and power or just use XML serialization to a file if you consider using SQLite an overkill. Or any of other viable options.
XML。 .NET 有一些类,可以进行处理xml 文件很容易。如果您要保存结构化数据,那么 XML 可能是您的最佳选择。
XML. .NET has classes that makes handling xml files easy. If you're saving structured data then XML might be your best bet.
出于非常相似的原因,我尝试了一些易于部署的数据库,但仍使用我所拥有的知识。
VistaDB 3.x 和 4 是我的第一选择,因为它们与 SQL Server 非常兼容,并且允许我切换到sql server 任何时候我喜欢。这也支持EF!!!
接下来是 Versant 的 db4o,非常方便。我主要将它用于快速原型设计,但我已经部署了几个小型解决方案,并且非常适合您的应用程序类型。
我希望这有帮助!
I have for very similar reasons tried some easy to deploy databases and yet use the knowledge i have.
VistaDB 3.x and 4 are my first choice because they are very much SQL Server compaible and allows me to switch to sql server anytime i like. This supports EF too!!!
Next is db4o by Versant which is very very handy. I use it mostly for quick prototyping but i have deployed to several small solutions and perfect for your kind of application.
I hope that helps!