问题
I have on a single Windows Server about 10 different .NET projects, mostly .NET 4.0 but some .NET 2.0
Some of these projects are asp.net, some are background utilities/services.
These projects interact with over a hundred different databases in our infrastructure. The ConnectionStrings they use to do that changes at least a few times a month.
The issue here is that forgetting to put a ConnectionString in one of these projects can cause a lot of problems, and new projects/updates are deployed to the server all the time by many different programmers.
My new attempt at a solution is to override the System.ConfigurationManager class in all projects and replace it with my own implementation that reads from a shared config file that I can maintain. Then I would just recompile each project once and deploy it.
I could also try to maintain the ConnectionStrings in the machine.config file that's shared between all projects, but I would have to do it for every version of the .NET framework used by a project which is at least three, and making a mistake in this file seems like it could be dangerous.
Does anybody have a recommendation of which way to proceed?
Thanks.
回答1:
Besides the machine.config, you can create common appSettings files. You won't need to develop anything new, just place your shared settings on this file and reference it on your specific config files.
Hope this helps.
Since the link is dead, here's a couple examples.
To fully load a section from an external file:
<connectionStrings configSource="ConnectionStrings.config" />
To complement a section from an external file (+ what's in the section itself):
<appSettings file="FileService.config">
...
</appSettings>
回答2:
Between the machine.config and the other solution there are the ALIAS. The limitation here is : it will do only for sql server.
来源:https://stackoverflow.com/questions/11363121/connectionstring-management-for-many-projects-on-one-server-should-i-make-my-ow