次の方法で共有


Using a Non-default Configuration Store

The Enterprise Library configuration tools allow you to specify the configuration source to be read at run time to configure your application. You can point to configuration files or other types of configuration sources from which to read configuration information. This topic explains how to add a non-default configuration source to your configuration. It uses the File-based Configuration Source, but the same approach is used with other configuration sources.

To add a configuration source

  1. On the taskbar, click Start, point to All Programs, point to Microsoft patterns & practices, point to Enterprise Library 5.0, point to Enterprise Library Configuration, and then select the version of the configuration editor you require. Alternatively, right-click on a configuration file in Visual Studio Solution Explorer and click Edit Enterprise Library V5 Configuration.

  2. Select Add Configuration Settings on the Blocks menu to display the section that contains the configuration sources.

  3. Click the Sources plus-sign icon, point to Add Sources, and then click Add File-based Configuration Source.

    Ff664467.7c6234f6-830b-4f56-b6bf-89b7b393fbfe(en-us,PandP.50).png

  4. A new section is added to the Sources pane with the default name of the type of configuration source you added, for example File-based Configuration Source. If you add more than one of the same configuration source type, the default names increment by one each time.

  5. Set the properties of the configuration source. For example, set the File Path property by typing the file path and name of the file, or by clicking the ellipsis button (…) and navigating to the file you want to use. The file can be located on the local machine, or in a shared location if you want to use the same configuration for multiple applications or application layers.

    Ff664467.961fcbb2-6011-4f53-ac4f-7e7677525269(en-us,PandP.50).png

  6. Edit the Name property of the configuration source if required.

  7. Click the Configuration Sources property expander chevron to open the properties pane for the section. Set the Selected Source property by selecting the configuration source you want to use for your application from the drop-down list.

    Ff664467.dc27d838-0405-41ae-99e3-c7158f981b24(en-us,PandP.50).png

  8. On the File, menu click Save or Save As.

Note

A QuickStart sample named SqlConfiguration that implements an example SQL Configuration Source to demonstrate how you can store configuration information in a database is available from the Enterprise Library Contrib Web site. This provider uses the Data Access Application Block to read configuration settings from a SQL Server© database.