How do I create a Solution Wide Connection String

房东的猫 提交于 2019-12-09 12:33:45

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/2620918/how-do-i-create-a-solution-wide-connection-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!