B Using Enterprise Library 4.1 : Data Access Application Block Overview

Data Access Application Block Overview
The Data Access Application Block (DAAB) is designed to allow developers to replace ADO.NET boiler-plate code with standardized code for everyday database tasks. The overloaded methods in the Database class can:
If your application needs to address specific DBMS functionality, you can use a DataDirect Connect for ADO.NET data provider.
Configuring the DAAB
Before you can configure the DAAB for use with your application, you must set up the environment:
1
2
3
4
Configuring the Data Access Application Block consists of two procedures:
Adding a New DAAB Entry
Now, use the Enterprise Library Configuration Tool to add a new DAAB entry:
1
Right-click Enterprise Library Configuration, and select New Application.
2
Right-click Application Configuration, then select New / Data Access Application Block. The Enterprise Library Configuration window appears.
Enterprise Library Configuration window
3
In the Name field, enter a name for the DAAB’s connection string, for example, MyOracle.
4
In the ConnectionString field, enter a connection string.
For example, Host=ntsl2003;Port=1521;SID=ORCL1252; User ID=SCOTT;Password=TIGER;Encryption Method=SSL;AuthenticationMethod=Kerberos;
5
Right-click the ProviderName field, and select the data provider. For example, select DDTek.Oracle.4.0 for the Oracle data provider.
6
Right-click Custom Provider Mappings and select New / Provider Mappings.
Enterprise Library Configuration window with the Oracle data provider selected under Custom Provider Mappings.
7
8
Select the TypeName field, and then choose the browse () button to navigate to the Debug output directory of the DataDirect DAAB that you built. Then, select the TypeName. For example, the Oracle TypeName is DDTek.EnterpriseLibrary.Data.Oracle.dll.
9
Adding the Data Access Application Block to Your Application
To add the DAAB to a new or existing application, perform these steps:
1
2
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
3
4
5
6
7
8
9
Using File Explorer, copy the DDTek.EnterpriseLibrary.Data.XXX.dll from the DataDirect DAAB directories, where XXX indicates the data source.
10
Using the Data Access Application Block in Application Code
Now that you have configured the DAAB, you can build applications on top of this DAAB.
In the following example, we use the DAAB MyOracle and the DatabaseFactory to generate an instance of a Database object backed by an Oracle data source.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
 
namespace DAAB_Test_App_1
{
    class Program
    {
        static void Main(string[] args)
        {
            Database database = DatabaseFactory.CreateDatabase("MyOracle");
            DataSet ds = database.ExecuteDataSet(CommandType.TableDirect, "SQLCOMMANDTEST_NC_2003SERVER_1");
               
        }
    }
}
The Microsoft Enterprise Library DAAB coding patterns are now at your disposal.