是否可以?
我们正在考虑将一些“硬编码”设置移出 Windows 窗体应用程序,并将它们存储在 SQL 数据库中名为 App_Settings 的表中。原因是我们当前将值硬编码到 appsettings 和 app.config 中,这些值可能会随着时间的推移而更改,并且更新数据库表中的值比更新、构建和部署应用程序要容易和快捷得多。三个服务器。
请有人对此提出建议,以及我们如何将设置加载到应用程序中,然后让它们在任何课程中随时可用?
干杯 理查德
We are thinking of moving some of the 'hard coded' settings out of our windows forms application and storing them in the sql database in a table called App_Settings. The reason for this is we have values currently hard coded into appsettings and app.config which can change over time, and it is much easier and faster to update the values in a database table than it is to update, build and deploy the app over three servers.
Please can someone advise on this, and also how can we load the settings into the app and then have them readily available in any class?
Cheers
Richard
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看这个类似的线程: Resources/App.config 或数据库是应用程序字符串的最佳位置
当您想在数据库中存储设置时,我会将类实现为 单例 或至少作为仅具有静态/共享成员和返回该单个/静态实例的工厂方法(getAppSettings)的类。因此,您可以从任何地方访问您的设置,并且仅初始化一次。
Have a look at this similar thread: Resources/App.config or Database where is the best place to application strings
When you want to store settings in the database i would implement the class as Singleton or at least as a Class with only static/shared members and a factory method(getAppSettings)which returns that single/static instance. So you could access your settings from everywhere and it is only initialized once.
为什么不使用 YAML 之类的东西来保存这些设置?创建一个表单来编辑这些设置并将其保存在文件中而不是数据库(这会增加更多的维护问题)会很容易。
否则,我建议使用 NHibernate 之类的东西来使用数据库,并使用 SQLLite 作为数据库服务器。
另外,请注意,如果您要更新这些设置,我不会说这些是 App_Settings,因为如果没有
帮助,App_Settings 通常无法修改,这会有所帮助,
彼得罗
Why don't you use something like YAML to save these settings? It would be easy to create a form to edit and save these settings in a file, instead of a db (which would add more maintainance problems).
Otherwise, I would suggest to use something like NHibernate to use a database, and SQLLite as the db server.
Also, note that if you are updating these settings, I would not say that these are App_Settings, since App_Settings aren't usually modifyable without
Help this helps,
Pietro