Share via


Using Alternate Configuration Sources

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

You can use other sources, such as a SQL database or the Enterprise Library Manageable Configuration Source to store your configuration information. The application configuration file contains a configuration section that defines the configuration source. If this section is missing, Enterprise Library uses the application configuration file as the configuration source. However, even if you use an alternate source, Enterprise Library saves your configuration information as XML.

The core configuration classes that support reading configuration information first try to read the requested configuration section from the configured source location. If the configuration section is not found, the core classes try to read the configuration section from the System Configuration Source.

The following procedures explain how to configure configuration sources:

  • Using an Alternate Configuration Source
  • Using the Application Configuration File
  • Using the File Configuration Source
  • Setting a Default Configuration Source

For information about the Enterprise Library Manageable Configuration Source, see Using Group Policy and WMI with Enterprise Library. For information about updating the Enterprise Library configuration at run time, see Updating Configuration Settings at Run-time.

Using an Alternate Configuration Source

The following procedure shows how you can specify any of the available configuration sources in the configuration tools.

To use an alternate configuration source

  1. Start the Enterprise Library Configuration Console or open the configuration file in the Visual Studio Configuration Editor. To use the Configuration Console, click Start, point to All Programs, point to Microsoft patterns & practices, point to Enterprise Library 4.1 — October 2008, and then click Enterprise Library Configuration.
  2. On the File menu, click New Application (if you are configuring a new application) or Open Application (if you are configuring an existing application).
  3. Right-click the Application Configuration node, point to New, and then click Configuration Sources.
  4. Right-click Configuration Sources, point to New, and then click the type of configuration source you want to use (such as File Configuration Source).
  5. Use the Properties pane to enter the desired configuration properties for the new configuration source.
  6. Select the Configuration Sources node, and then select the SelectedSource property in the Properties pane.
  7. Click the arrow adjacent to System Configuration Source, and then click the configuration source you want to use.
  8. After you make your configuration changes, click File, and then click Save Application.

Note

The Enterprise Library source code contains a QuickStart named SqlConfiguration that implements an example SqlConfigurationSource to demonstrate how you can store configuration information in a database.

Using the Application Configuration File

By default, the Enterprise Library configuration tools place configuration information in the application configuration file (which is also the default configuration location for applications).

To use an application configuration file

  1. Start the Enterprise Library Configuration Console or open the configuration file in the Visual Studio Configuration Editor. To use the Configuration Console, click Start, point to All Programs, point to Microsoft patterns & practices, point to Enterprise Library 4.1 — October 2008, and then click Enterprise Library Configuration.
  2. Click New Application or Open Existing Application.
  3. Right-click Application Configuration, point to New, and then click Configuration Sources.
  4. The console adds the default System Configuration Source node. If you want to modify its properties, click this node.
  5. (Optional) Type a new name for the System Configuration Source node. The default name is System Configuration Source.

Using the File Configuration Source

You can use configuration sources other than the application configuration file. The following procedure describes how to do this.

To use alternative configuration sources

  1. If you want to use a configuration source other than System Configuration Source, right-click Configuration Sources, point to New, and then click File Configuration Source.
  2. Set the File property. To do this, type the name of the file or click the ellipsis button (…), and then click the file you want to use.
  3. (Optional) Set the Name property. To do this, type a new name for the File Configuration Source node. The default name is File Configuration Source.

Setting a Default Configuration Source

You can also select the default configuration source for an application. The following procedure describes how to do this.

To set the default configuration source

  1. Click the Configuration Sources node.
  2. Change the SelectedSource property. To do this, either type the name of another configuration source or click a name in the drop-down list.