Validation Application Block

Published 11/29/2006 by Henry in EntLib

As I am a subscriber to the Patterns and Practices newsletter, it came to my attention that the Enterprise library will be extended with a new Application Block:
The Validation Application Block.

the first thing that sprung into mind was that the Enterprise Library is growing more and more to an adult stage in it's life, when the team has time to make a validation App Block, the rest of the Library must be performing pretty good!
Not that I think Validation isn't important, but I figure there are other aspects of Enterprise Development that need attention before you think about Validation.

Still I immediately see the pro's. I remember an interview with architects from a very technical company (robot steering), about 6 months ago. They boasted about the classes they made to make their apps connect to SQL Server as well as to Oracle. When I mentioned the Enterprise Library, where one of the first features was just that.
I mean, why invent the wheel, when there is the Enterprise Library?

The point I am trying to make is, "Guys there is going to be a Validation Application block in EntLib!".

The possibilities are, to define validation rules through .config XML files (configuration files), that can be edited etc. through the Enterprise library Configuration Console.
And you can do the defining of the validation rules in code, which ofcourse automatically provides encapsulation and the certainty the rules are not going to change unless there is a code change (or a new release).
In Tom Hollanders blog everything is revealed

Henry Cordes
My thoughts exactly...

Enterprise Library (.NET 2.0) release

Published 1/21/2006 by Henry in EntLib

The long-awaited update to Enterprise Library for .NET Framework 2.0 is now available - the official release is branded January 2006.

Enterprise Library for .NET Framework 2.0 Now Available! 

Enterprise Library for .NET 2.0

This release of Enterprise Library includes six application blocks (Caching, Cryptography, Data Access, Exception Handling, Logging and Security), and provides similar functionality to the previous releases for the .NET Framework 1.1; however, Enterprise Library has been redesigned to use the new capabilities of the .NET Framework 2.0.

Go to patterns & practices: Enterprise Library


Henry Cordes
My thoughts exactly...

The so-called "Interim community drop" of Enterprise Library for .NET Framework 2.0 is available, although not a official release, it includes the long-awaited configuration tool. What makes the Enterprise Library useful is among other things the Configuration Tool. So now it is possible to try the .Net Framework 2.0 version of the enterprise Library.  
The Cryptography Application Block is the only block that is not quite ready, the other blocks should be 99% ready.

It can be found at: GotDotNet and at Tom Hollander,s blog:
The configuration tool can be found in \src\Configuration\Console, by the way.

Henry Cordes
My thoughts exactly...

The November Community Technology Preview of the Enterprise Library for .NET Framework 2.0 is released.
The Enterprise Library (CTP)  has been redesigned to take advantage of key new features in the .NET Framework 2.0, and also includes various new features and enhancements.
More information can be found in this area of the Patterns & Practices area of Microsoft's website.

The final release of Enterprise Library for .NET Framework 2.0 is expected to be in December 2005.

The application blocks that comprise the Enterprise Library for .NET Framework 2.0 are the following:

  • Caching Application Block.
  • Data Access Application Block.
  • Exception Handling Application Block.
  • Logging Application Block.
  • Security Application Block.


In addition, the Enterprise Library Core provides services such as instrumentation and configuration, and is a shared dependency of all Enterprise Library application blocks.
Developers who are familiair with the Enterprise Library will have noticed that the Configuration Application Block no longer is a part of the Enterprise Library. Most of the configuration functionality supported by the old block is now provided by the System.Configuration namespace in .NET Framework 2.0. All Enterprise Library application blocks now leverage this functionality. The Enterprise Library core still includes some helper classes for configuration, as well as the configuration design-time components and tool.

Deployment in low-rights environments
All Enterprise Library application blocks are instrumented with performance counters, WMI and event logs, as was the case in previous releases. By default, all instrumentation is disabled and the application blocks can now be deployed using XCOPY in low-rights environments such as ASP.NET.

The Enterprise Library Configuration Console is not available in the November 2005 CTP release. To change an application’s configuration, one has to edit its XML configuration file.

Henry Cordes
My thoughts exactly...

Data Access Application Block (EntLib)

Published 9/22/2005 by Henry in EntLib

When I first started working with the Enterprise Library, I found it hard to find information about how to use it. I even heard a story about a developing-team that decided not to use it because they could not figure out fast enough how to use it.
So I will try to make some sort of Data Access Application Block walkthrough and hope this will make it easier for people to start using the Enterprise Library.

Consuming app
Suppose we got a webapplication with one page. We are going to use the Northwind database. In the Northwind database there is a stored procedure called:
which needs the parameter:
@CustomerID nvarchar(5).

On the page in our webapp we got a Datagrid. In this grid we want to show the data that the stored procedure returns.
We are going to use the Data Access Application Block for access to the database.

Web Application
First we create a web Application. The language I use is C#. I renamed the WebForm1.aspx to Default.aspx and put a datagrid on the page and named it dGrid, I left 'Auto Generate Columns' checked. Enterprise Library Configuration (Tool) Next we open the Enterprise Library Configuration Tool, we click on ‘File’ > ‘Open Application” or click the ‘Open’ icon.

Open application 
Open Existing Application

Browse to the directory where the web.config of the Web Application is located selected it and click on ‘Open’. Now we see the following:

New application 
New Application

You can rename the ‘Application’ node, I named it ‘WebAppEntLib’. You right-click the ‘Application’ node and choose ‘New’ > ‘Data Access Application Block’.

New dataaccesappblock 

As you see the DAAB (Data Access Application Block) is installed (with the Configuration Application Block).


Configuration Application Block
The ‘Configuration Application Block’ is installed with the Data Access Application Block and is used to store the information about which method is used to store the config information (XML File) and where this XML based dataacces config file can be found. By chancing the ‘FileName’ under ‘XML File Storage Provider’ under the ‘dataConfiguration’ node in the name with a directory name before the name (\dataConfiguration.config) you can control where the config file will be stored. If you don’t do this the file will be in the same directory as the web.config or app.config file.

Data Access Application Block
With the Configuration Tool we make the configuration settings needed to make the Data Acces Block work for us. Database Types With this node it is possible to define other database types (Oracle, MySql etc.). With the Enterprise Library the Oracle database type is included and can easily be chosen.

Oracle db
Oracle database

Sql Connection String
With the Sql Connection String node the connectionstring used to connect to the database can be defined.
Default the following nodes are provided, we use the following values:

  • Database - ‘Northwind’
  • Integrated Security - ‘False’
  • Server - ‘(local)’

We also need the nodes (with the following values):

  • Uid (userid) - ‘developer’
  • Pwd (Password) - ‘developer’

Through a right click and choosing the menu’s new > ‘parameter’ and supplying as name ‘uid’ with the Value the username we need to connect to our database (in our case ‘developer’).
And once more with New > Password parameter we supply ‘pwd’ as Name and in our case ‘developer’ as password (by clicking the ellipse).
We also change the default node name ‘SQL Connection String’ into ‘Northwind Connection String’ by right clicking the node name and choosing ‘Rename’.

Database Instances
With the Database Instances node we define database instances. A great benefit from the Data Access Application Block is that it is relatively easy to make an application communicate with multiple databases. We define which Connectionstring, Database Type and Name of the Database we are going to use through this node.

  • Connectionstring node - ‘Northwind Connection String’ (dropdown)
  • DatabaseTypeNode - ‘Sql Server’ (dropdown) Name - ‘Northwind’

choose databasetypenode 

We save this settings with File > Save Application or through the disk icon. All settings now are written in the dataconfiguration.config file <P align=left>We save this settings with File &gt; Save Application or through the disk icon.<BR>All settings now are written in the dataconfiguration.config file.<BR></P>


 <xmlSerializerSectiontype="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=, Culture=neutral, PublicKeyToken=null">
<enterpriseLibrary.databaseSettingsxmlns:xsd="Northwind" xmlns="">
    <databaseTypename="Sql Server"type="Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase, Microsoft.Practices.EnterpriseLibrary.Data, Version=,   Culture=neutral, PublicKeyToken=null"/>
    <instancename="Northwind"type="Sql Server"connectionString="Northwind Connection String"/>
    <connectionStringname="Northwind Connection String">
      <parametername="Integrated Security"value="False"isSensitive="false"/>
      <parametername="pwd"value="developer"isSensitive="true"/> <parametername="server"value="(local)"isSensitive="false"/>

In Visual Studio we highlight our project and select Project > Add Reference. On the .NET tab, we use "Browse..." to locate and set references to the following dll's:


  • Microsoft.Practices.EnterpriseLibrary.Configuration
  • Microsoft.Practices.EnterpriseLibrary.Data

Now we open the code-behind file for our startingpage: default.aspx.cs and add the following directives:

using Microsoft.Practices.EnterpriseLibrary.Data;using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

In default.aspx code-behind we create the method BindDataFromDAAB(), which we call in the Page_Load() 

   1:  private void BindDataFromDAAB()
   2:  { 
   3:      DataRow dataRow; 
   5:      DataTable dataTable = new DataTable(); 
   6:      dataTable.Columns.Add(new DataColumn("OrderID", typeof(Int32))); 
   7:      dataTable.Columns.Add(new DataColumn("OrderDate", typeof(DateTime))); 
   8:      dataTable.Columns.Add(new DataColumn("RequiredDate", typeof(DateTime))); 
   9:      dataTable.Columns.Add(new DataColumn("ShippedDate", typeof(DateTime))); 
  11:      //Create a database object 
  12:      Database dataBase = DatabaseFactory.CreateDatabase(); 
  13:      //In case of multiple databases 
  14:      //Database dataBase=DatabaseFactory.CreateDatabase("Northwind"); 
  16:      //Create command wrappers to specify parameters 
  17:      DBCommandWrapper dbCommandWrapper = dataBase.GetStoredProcCommandWrapper("CustOrdersOrders"); 
  18:      //Fill parameter 
  19:      dbCommandWrapper.AddInParameter("@CustomerID", DbType.String,"BOTTM"); 
  21:      using (IDataReader dataReader = dataBase.ExecuteReader(dbCommandWrapper))
  22:      { 
  23:          while (dataReader.Read())
  24:          { 
  25:              dataRow = dataTable.NewRow(); 
  26:              // 0 
  27:              OrderID, string dataRow[0] = dataReader.Int32(0); 
  28:              // 1 
  29:              OrderDate, datetime dataRow[1] = dataReader.GetDateTime(1); 
  30:              // 2 
  31:              RequiredDate, datetime dataRow[2] = dataReader.GetDateTime(2); 
  32:              // 3 
  33:              ShippedDate, datetime dataRow[3] = dataReader.GetDateTime(3); 
  34:              dataTable.Rows.Add(dataRow); 
  35:          } 
  36:          dataReader.Close(); 
  37:      } 
  38:      dGrid.DataSource = dataTable; 
  39:      dGrid.DataBind();
  40:  }

This code is pretty unreusable, but I think it gets the point across.
In the real world you could make a dataacces class to do all the database related stuff, a class Orders in which all the Orders related stuff would be. So you would not have all the data and business logic in the webpage code-behind. 

Henry Cordes 
My thoughts exactly...