Adding Application Code

The Data Access Application Block is designed to support the most common scenarios for accessing a database. When you add your application code, refer to the scenarios in the Key Scenarios section and select the ones that best match your situation. Use the code that accompanies the scenario as-is or adapt it as necessary.

First, you must prepare your application to use the Data Access Application Block. After you do that, you can create the Database object and call the appropriate method overloads.

To prepare your application

  1. Add a reference to the Data Access Application Block assembly. In Visual Studio, right-click your project node in Solution Explorer, and then click Add Reference. Click the Browse tab, and then navigate to the location of the Microsoft.Practices.EnterpriseLibrary.Data.dll assembly. Select the assembly, and then click OK to add the reference.

  2. Following the same procedure, add references to the following assemblies:

    • Microsoft.Practices.EnterpriseLibrary.Common.dll
    • Microsoft.Practices.Unity.dll
    • Microsoft.Practices.ServiceLocation.dll
    • Microsoft.Practices.Unity.Interception.dll.
  3. (Optional) To use elements from Data Access Application Block without fully qualifying the element reference, you can add the following using statement (C#) or Imports statement (Visual BasicĀ®) to the top of your source code file.

    using Microsoft.Practices.EnterpriseLibrary.Data;
    using System.Data;
    
    'Usage
    Imports Microsoft.Practices.EnterpriseLibrary.Data
    Imports System.Data
    

Note

For Visual Basic projects, you can use the References page of the Project Designer to manage references and imported namespaces. To access the References page, select a project node in Solution Explorer. On the Project menu, click Properties. When the Project Designer appears, click the References tab.

For information on how to create a Database object and advice on using the Database types, see Creating a Database Object.

For information about the key scenarios for using the block, see Key Scenarios.