本文介绍了我如何在一个机器范围内的连接字符串位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,在Machine.config中,您可以添加连接字符串,这样就不需要每个运行的应用程序配置文件中的连接字符串。不利的一面是您有许多框架版本* 2 machine.config文件。因此,对于版本4. *,您只有2个。经过我的研究,发现可以使用machine.connectionString元素中的configSource属性来外部化连接字符串。

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" />

但是,人们意识到配置源必须位于machine.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?

推荐答案

我在任何地方都找不到在互联网上有这个答案。因此,我将在做一些实验后亲自回答这个问题。

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


  1. 创建一个位置,并将其中的connectionstrings.config文件放置在其中。例如C:\Test\Connectionstrings.config

  1. Create a location and place your connectionstrings.config file in there. Ex. C:\Test\Connectionstrings.config

  1. 在每个machine.config位置。例如C:\Windows\Microsoft.net\Framework64\v4。* \Config。执行步骤3和4

  2. 以管理员身份打开命令提示符到该位置,然后运行命令: C:\Windows\Microsoft.NET\Framework64 \v4.0.30319\Config> mklink / D Config C:\Test

  3. 将machine.config编辑为< ; connectionStrings configSource = Config\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.

这篇关于我如何在一个机器范围内的连接字符串位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 22:00