如何创建解决方案范围的连接字符串
有谁知道是否可以创建一个可供解决方案中的所有项目访问的单个连接字符串(我们大约有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定,您不能将新的配置文件放入解决方案项并将其包含并加载到所有项目中吗?
编辑:我具体讨论的是通用(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.
将连接字符串放入“主”项目的配置中。创建具有连接字符串属性的数据访问项目。在初始化项目时设置此属性,并将数据访问项目用于所有 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