Entering Configuration Information

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.

The following procedures describe how to configure the Data Access Application Block. Properties associated with the nodes appear in the right pane of the Configuration Console or the Properties window of the Visual Studio Configuration Editor. For details of the schema for the Data Access Application Block configuration, see Source Schema for the Data Access Application Block.

To add the Data Access Application Block

  1. Open the configuration file. For more information, see Configuring Enterprise Library.
  2. Right-click Application Configuration, point to New, and then click Data Access Application Block.

The next procedure explains how to configure an instance of the default database. This instance is used if the application calls the DatabaseFactory.CreateDatabase method with no instance name.

To configure the default database

  1. In the right pane, expand the DefaultDatabase property.
  2. Enter the connection string name for the DefaultDatabase property or select it from the drop-down box. The default connection string name is ConnectionString.
  3. (Optional) Set the Name property by typing a new name. The default name is ConnectionString.
  4. In the ProviderName property section, change the provider name as required. Enter the name of the provider or select it from the drop-down list. The default provider name is System.Data.SqlClient. The ProviderName property must be a provider name specified in a DBProviderFactory class.

The next procedure explains how to create the connection string for a named database instance. When the configuration tools save the connection string, they generate a colon-delimited string that stores the connectin information as a series of name=value pairs. For example, if you used the configuration tools to create a connection string with all the default values, they would generate the following connection string.

Database=Database;Server=(local)\SQLEXPRESS;Integrated Security=SSPI;

To configure a connection string

  1. Click the ConnectionString node.
  2. (Optional) Set the Name property by typing a new name. This is the name of the ConnectionString node. The default name is ConnectionString.
  3. (Optional) In the ProviderName property section, change the provider name. Enter the name of the provider or select it from the drop-down list. The default provider name is System.Data.SqlClient. The ProviderName property must be a provider name specified in a DbProviderFactory class.
  4. Update the ConnectionString property as required. For example, this connection string specifies the local SQL Server Express named database instance using itegrated Windows security:

The next procedure describes how to configure a SQL Server CE database. These steps are appropriate if your application always uses a single file that you name during configuration. For more information about SQL Server CE, see Creating a Database Object.

To configure SQL Server CE

  1. Right-click Custom Provider Mappings, point to New, and then click Provider Mapping.
  2. Click the Name property entry in the Properties pane. In the drop-down list, select Microsoft.SqlServerCe.Client.
  3. Click in the TypeName property entry in the Properties pane, and then click the ellipsis button (****…).
  4. In the Type Selector, double-click SqlCeDatabase.
  5. Right-click the ConnectionStrings node, point to New, and then click Connection String.
  6. (Optional) Set the Name property by typing a new name. This is the name of the ConnectionString node. The default name is ConnectionString.
  7. In the ProviderName property section, change the provider name to Microsoft.SqlServerCe.Client.
  8. In the ConnectionString property section, enter the desired SQL Server CE connection string, for example:

The next procedure describes how to add Oracle packages. An Oracle package serves as a way to group stored procedures into common groups, typically based on their functionality. When an application calls an Oracle stored procedure located in a package, the code must prefix the stored procedure name with the package name. For example, to call a procedure named GetEmployeeName that is in a package named Employee_pkg, you would call Employee_pkg.GetEmployeeName.

Incorporating this code into the application makes it less portable because this syntax is specific to Oracle. Instead, the Data Access Application Block can prefix the stored procedure with the package name. This means your client code does not need to specify the package name to call a stored procedure. To do this, the application block uses information in the configuration file. The OraclePackage node stores a name/prefix pair. The name is the name of the package. The prefix is a string that is associated with the package. All stored procedures that start with that prefix are assumed to be in the associated package.

When the application calls a stored procedure, the Data Access Application Block checks to see if it begins with any of the prefixes in the configuration file. If it does, the application block prefixes the stored procedure with the associated package name. (The first match it finds is the one the application block uses.) If you specify an asterisk ("*") as the prefix, the associated package is used for all stored procedure calls.

To configure an Oracle package

  1. Right-click ConnectionString, point to New, and then click OraclePackages.
  2. Click Oracle Package.
  3. Change the Name property by entering the name of the Oracle package. The default name is OraclePackage.
  4. Enter a value for the Prefix property.

The next procedure describes how to add custom provider mappings by associating a provider with the fully qualified name of a database.

To configure a custom provider

  1. Right-click the CustomProviderMappings node, point to New, and then click ProviderMapping.
  2. (Optional) Set the Name property by typing a new name. Enter the name of the provider or select it from the drop-down list. The default provider name is System.Data.SqlClient. The ProviderName property must be a provider name specified in a DbProviderFactory class.
  3. In the TypeName property section, click the ellipsis button (****…) and use the Type Selector to select the fully qualified name of the Enterprise Library database type.

Usage Notes

There are two points to remember about configuration files:

  • When you use the configuration tools to open an existing application configuration file that includes the Data Access Application Block, they display connection strings stored in the Machine.config file. Although the graphical user interfaces allow you to edit these connection strings, the configuration tools cannot modify the Machine.config file and none of the changes take effect. The configuration tools only save the changes you make to connection strings stored in your application file.
  • The configuration files are not encrypted by default. A configuration file may contain sensitive information about connection strings, user IDs, passwords, database servers, and catalogs. You should protect this information against unauthorized read/write operations by using encryption techniques. For information about how to encrypt configuration files, see Configuring Enterprise Library.