如何创建解决方案范围的连接字符串

发布于 2024-08-28 16:47:15 字数 208 浏览 5 评论 0原文

有谁知道是否可以创建一个可供解决方案中的所有项目访问的单个连接字符串(我们大约有 6 个)。

我可以使用此信息创建一个文本文件,但我们还需要设计时支持,并且在解决方案中的每个 App.Config 和 Web.config 文件中都有连接字符串是不切实际的。

我们基本上想要一个单一的连接字符串,如果数据库的位置发生变化,它很容易更改,IDE 也将使用它来提供设计时支持

Does anyone know if it is possible to create a single connection string that will be accessible to all the projects in a solution (we have about 6).

I can create a text file with this information, but we need design time support as well, and it is not practical to have a connection string in every App.Config and Web.config file in the solution.

We basically want a Single connection string that is easy to change should the location of the db change, that will also be used by the IDE for design time support

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

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

发布评论

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

评论(2

記柔刀 2024-09-04 16:47:15

不确定,您不能将新的配置文件放入解决方案项并将其包含并加载到所有项目中吗?

编辑:我具体讨论的是通用(XML)配置文件,而不是“App.config”。其格式完全相同,只是名称不同。将此文件添加到您的解决方案项目中,并使用 OpenMappedExeConfiguration
您可以在此处找到其他示例。

Not sure, can't you just put a new config file to the solution items and include and load it in all projects?

Edit: I am specifically talking about a general (XML) config file, not an "App.config". Is has exactly the same format, it just goes by a different name. Add this file to your solution items and access it using OpenMappedExeConfiguration.
You can find an additional example here.

呆橘 2024-09-04 16:47:15

将连接字符串放入“主”项目的配置中。创建具有连接字符串属性的数据访问项目。在初始化项目时设置此属性,并将数据访问项目用于所有 6 个项目中的所有数据库相关操作

put the connection string in the config of your "main" project. Create a Data Access project with a connectionstring property. Set this property when you initialise your project and use the Data Access project for all database related actions in all 6 projects

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