我应该在哪里存储用户配置数据?具体是数据文件的路径?

发布于 2024-08-26 19:59:37 字数 261 浏览 4 评论 0原文

我有一个使用 SQLite 数据库的应用程序,我需要用户能够移动数据文件并将应用程序指向它移动到的位置。我使用实体框架创建模型,默认情况下它将连接字符串放入 App.Config 文件中。根据我所读到的内容,如果我对连接字符串进行更改,那么只有重新启动应用程序后它们才会生效。这对我来说似乎有点笨拙。我了解如何初始化模型并传入自定义字符串,但我不确定存储基本用户首选项的最佳实践是什么? Ini、注册表还是其他地方?我不希望用户每次都必须“打开”文件,只是当文件重新定位时,应用程序才会尝试从那时起自动打开。

I have an app using a SQLite db, and I need the ability for the user to move the data file and point the app to where it moved to. I used the Entity Framework to create the model, and by default it puts the connection string in the App.Config file. From what I've read if I make changes to the connection string there then they won't take effect until the app is restarted. That seems a bit clunky for my use. I see how I can init my model and pass in a custom string but I'm unsure what the best practice is in where to store basic user prefrences such as this? Ini, Registry, somewhere else? I don't want the user to have to "Open" the file each time, just when it relocates and then the app will try to auto open from then on.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

终难遇 2024-09-02 19:59:37

查看应用程序设置了解概述介绍如何创建可以保存到 user.config 文件的用户特定配置设置。注册表或多或少被放弃,取而代之的是新的基于 xml 的配置文件系统。

Have a look at Application Settings for an overview of how to create user-specific config settings which can be saved to a user.config file. The registry is more or less abandoned in favour of the new xml-based config file system.

雄赳赳气昂昂 2024-09-02 19:59:37

您不必使用添加到 App.Config 中的连接字符串。您可以在 EDMX 向导中跳过实际添加。

然后,您只需将连接字符串放在您选择的任何位置并将其传递到 ObjectContext 构造函数中即可。

您可以将连接字符串放在外部文件、注册表或您选择的任何位置。

使用一个静态类来生成连接字符串,并从用户可以更改的公共源(即注册表、磁盘上的文件、环境变量等)获取文件位置可能是有意义的。

You don't have to use the Connection String that is added to the App.Config. You can skip adding it actually, in the EDMX wizard.

You then need simply have the connection string live anywhere you choose and pass it into your ObjectContext constructor.

You can put the connection string in an external file, the registry, or wherever you choose.

It might make sense to have a static class that generates the connection string, and grabs the file location from a common source that the user can change (i.e. registry, file on disk, environment variable, etc.)

︶ ̄淡然 2024-09-02 19:59:37

您可以创建一个设置类,然后将其序列化为一个 xml 文件,该文件的预定义名称位于通过 app.config 文件设置的位置。然后,您可以自己控制将文件读入内存的频率。唯一需要重新启动应用程序的情况是设置文件的位置发生更改。

You could create a settings class and then serialise it to an xml file with a predfined name in a location that is set via the app.config file. You could then control how frequently the file was read into memory yourself. The only timeyou would need to restart the app was if the location of the settings file changed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文