简体   繁体   English

一台服务器上许多项目的ConnectionString管理,我应该为我们的代码创建自己的ConnectionString提供程序

[英]ConnectionString management for many projects on one server, should I make my own ConnectionString provider for our code

I have on a single Windows Server about 10 different .NET projects, mostly .NET 4.0 but some .NET 2.0 我在一个Windows Server上有大约10个不同的.NET项目,主要是.NET 4.0,但有一些.NET 2.0

Some of these projects are asp.net, some are background utilities/services. 这些项目中有一些是asp.net,一些是后台实用程序/服务。

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. 他们用来执行此操作的ConnectionString每月至少更改几次。

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. 这里的问题是,忘记将ConnectionString放在这些项目之一中会导致很多问题,并且许多不同的程序员始终将新项目/更新部署到服务器上。

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. 我对解决方案的新尝试是在所有项目中覆盖System.ConfigurationManager类,并用我自己的实现替换它,该实现从我可以维护的共享配置文件中读取。 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. 我也可以尝试在所有项目之间共享的machine.config文件中维护ConnectionStrings,但是对于至少三个项目使用的.NET框架的每个版本,我都必须这样做,并且在该文件似乎很危险。

Does anybody have a recommendation of which way to proceed? 是否有人建议采用哪种方式进行?

Thanks. 谢谢。

Besides the machine.config, you can create common appSettings files . 除了machine.config之外,您还可以创建常见的appSettings文件 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>

Between the machine.config and the other solution there are the ALIAS . 在machine.config和其他解决方案之间是ALIAS The limitation here is : it will do only for sql server. 此处的限制是:仅适用于sql server。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM