Export (0) Print
Expand All

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 show how to configure the Data Access Application Block.

This procedure explains how to configure the Data Access Application Block. Properties associated with the nodes appear in the right pane.

To add the Data Access Application Block

  1. Open the configuration file. For more information, see Configuring the Application Blocks.
  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 dropdown 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 if you want to. 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 console saves the connection string, it generates a colon-delimited string that stores the pairs in a name = value format. For example, if you used the configuration console to create a connection string with all the default values, the configuration console 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 with the following value:
    Database=Database;Server=(local)\SQLEXPRESS;Integrated Security=SSPI
    
    

The next procedure shows 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 Details of Creating a Database Object.

To configure SQL Server CE

  1. Right-click Custom Provider Mappings, point to New, and click Provider Mapping.
  2. Click on the Name property entry in the Properties pane. From the drop down list select Microsoft.SqlServerCe.Client.
  3. Click in the TypeName property entry in the Properties pane. Click the ellipsis (…) button.
  4. In the Type Selector, locate and double-click on SqlCeDatabase.
  5. Right-click on the ConnectionStrings node and click New, then 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:
    Data Source='C:\MyApp\MyDatabase.sdf'
    
    

The next procedure shows 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 is syntax that 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 associated package name to the stored procedure. (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 OraclePackage.
  3. Change the Name property by entering the name of the Oracle package. The default is OraclePackage.
  4. Enter a value for the Prefix property.

The next procedure explains 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 console to open an existing application configuration file that includes the Data Access Application Block, it displays connection strings stored in the Machine.config file. Although the configuration console's GUI interface allows you to edit these connection strings, the configuration console cannot modify the Machine.config file and none of the changes take effect. The configuration console only saves the changes you make to connection strings stored in your application file.
  • The configuration files are not encrypted. 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 the Application Blocks.

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.
Show:
© 2014 Microsoft