问题
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