How do I have one location for connection strings machine wide?

我的未来我决定 提交于 2019-12-01 11:07:45

问题


I have found that in the Machine.config you can add your connection strings so that you don't need your connection strings in each running apps config file. The down side to this is that you have number of framework versions * 2 machine.config file. So for version 4.* you have 2 alone. This took my research on to find that you can externalize the connection string using the configSource attribute in the connectionString element of the machine.config

<connectionStrings configSource="Config\connectionStrings.config" />

However, one realizes that the config source must be in a subfolder of where the the machine.config file is located. So how do you have one, machine wide, location to store all your connection strings?


回答1:


I couldn't find anywhere on the internet that had this answer. So I am going to answer this myself after some experimentation.

  1. Create a location and place your connectionstrings.config file in there. Ex. C:\Test\Connectionstrings.config
    1. In each of the machine.config locations. For example C:\Windows\Microsoft.net\Framework64\v4.*\Config. Do steps 3 and 4
    2. Open up command prompt as administrator to the the location and run the command:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config>mklink /D Config C:\Test
    3. Edit the machine.config to be <connectionStrings configSource="Config\connectionStrings.config" />

Now you have one location for all your connection strings.



来源:https://stackoverflow.com/questions/32400437/how-do-i-have-one-location-for-connection-strings-machine-wide

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