有谁知道是否可以创建一个可供解决方案中的所有项目访问的单个连接字符串(我们大约有 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
发布评论
评论(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