Skip to main content

Microsoft enterprise data application blocks

.
Microsoft enterprise data application blocks is an excellent data access layer component which can be used to reduce the coding effort for database applications significantly. Its a free download from MSDN

The goals of Enterprise Library are the following:
  1. Consistency. All Enterprise Library application blocks feature consistent design patterns and implementation approaches.
  2. Extensibility. All application blocks include defined extensibility points that allow developers to customize the behavior of the application blocks by adding their own code.
  3. Ease of use. Enterprise Library offers numerous usability improvements, including a graphical configuration tool, a simpler installation procedure, and clearer and more complete documentation and samples.
  4. Integration. Enterprise Library application blocks are designed to work well together or individually.
Links to download various versions of Microsoft enterprise library
  1. For .Net framework 3.5 - http://msdn.microsoft.com/en-us/library/dd203099.aspx
  2. For .Net framework 2.0 - http://msdn.microsoft.com/en-us/library/aa480453.aspx
  3. For .Net framework 1.1 - http://www.microsoft.com/downloads/details.aspx?FamilyId=A7D2A109-660E-444E-945A-6B32AF1581B3&displaylang=en
More details are available in http://www.codeplex.com/entlib

  1. How to set up and use Enterprise library data application block data access layer
  2. Download and Install the MSI file
  3. Reference the following DLLs from the bin folder of your installed path (for me it was in C:\Program Files\Microsoft Enterprise Library 3.1 - May 2007\Bin) to your .Net application
    • Microsoft.Practices.EnterpriseLibrary.Common.dll
    • Microsoft.Practices.EnterpriseLibrary.Data.dll
    • Microsoft.Practices.ObjectBuilder.dll
  4. Thats it you are now ready to use the classes and functions available in the Enterprise library data application block DAL
Below are some code samples on how to use data application blocks to perform data access operations

1. General structure

//Add the following Using statements at the top of the Class file
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
----
//initalize the Database object using the ConnectionString name
Database db = DatabaseFactory.CreateDatabase(Connection string name from web.config);
//Execute an SQL Query using the Execute methods available
db.ExecuteFunctionName(Stored Procedure Name, comma seperated parameters);
//This is the common structure I use in my projects.
//You can find lot of other ways to execute db queries like
//passing the row Command instead of SPROC name.

2. Insert, Update and Delete

//For insert, update and delete use ExecuteNonQuery
Database db = DatabaseFactory.CreateDatabase("ConString");
db.ExecuteNonQuery("usp_user_insert", username, emailID, password);

3. Returning Single values

//If your SPROC return single value, use ExecuteScalar
object pollID = db.ExecuteScalar("usp_poll_insert", question);

4. Selecting data

//use ExecuteDataSet to select data
DataSet ds = db.ExecuteDataSet("usp_users_select");


Just imagine how many lines of code it can easily reduce to execute a query which have a number of parameters.

From now on I will use this Enterprise library data application block data access layer for all the code samples in this blog.

NOTE: The Microsoft Enterprise Library coryntains lot of other really useful Application blocks such as Caching Application block and Cryptography Application Block.
.

Comments

Popular posts from this blog

Asp.Net CAPTCHA and Asp.Net AJAX CAPTCHA

I am using a great Asp.Net CAPTCHA by BrainJar in a number of web sites with and without Asp.Net AJAX. It’s a simple and really easy to use Asp.Net CAPTCHA. The actual source code is in C#, but you can use it with both C# and VB.Net by simply wrapping the functionality in a class library. In Asp.Net forums and in many other user communities I have seen lot of people asking for VB.Net CAPTCHA. So I thought to write a blog post and create some sample implementations. The zip file contains C# CAPTCHA and VB.Net CAPTCHA. I have included the samples for Asp.Net AJAX CAPTCHA also. You can download the samples and implementation from here Implementing Asp.Net AJAX CAPTCHA is really simple. Just wrap the main Asp.Net CAPTCHA with Asp.Net AJAX update panel and put a random query string at the end of CAPTCHA image src. The random query string will avoid showing the old CAPTCHA from browser cache. STEPS TO ADD ASP.NET CAPTCHA IN YOUR WEBSITE Refer the assembly CaptchaDLL.dll in your project Copy...

Import/Export data with SQL Server 2005 Express - DTS Wizard

After using the simple sql server 2005 data transfer utility for some days I thought to add more functionality such as import export data from excel, CSV, flat file etc. Before start coding I just did a Google search and found this big and interesting discussion in MSDN forums. In the first page developers were really annoyed with the fact MS is not giving a data transfer utility with Sql Server Management Studio Express. I read the conversation one by one and in the 5th page I found this posting by Bill Elicson. MS actually has a really great DTS tool for sql server management studio express. Thanks Bill.. you saved alot of time. STEPS TO ADD DTS WIZARD WITH SQL SERVER MANAGEMNT STUDIO EXPRESS 1. Try "C:\Program Files\Microsoft SQL Server\90\DTS\Binn\DTSWizard.exe" If it worked, you already have the DTS Wizard. Start using it right away. If it will not work, continue to step 2 2. Download the Microsoft SQL Server 2005 Express Edition Toolkit (223.9 MB) from http://go.mi...

Simple Numeric Pagination for DataList and Repeater

There are a big number of tutorials available on how to implement pagination in asp.net DataList and Repeater. But all of them are explaining only about the Next/Prev mode of pagination only. Recently I have implemented a quick and dirty numeric pagination on DataList for one of my project. The idea is simply use a PagedDataSource to get the current page of data and bind it to DataList or Repeater. Now create dynamic Linkbuttons using the PageSize and the Total rows count. See the code below. ASPX Code <head runat="server"> <title>Untitled Page</title> <style type="text/css"> .pagination a{padding:5px;} .pagination span{padding:5px;} </style> </head> <body> <form id="form1" runat="server"> <div> <asp:DataList ID="dlPaginationSample" runat="server"> <ItemTemplate> <%# Eval("Column1")%> | <%# Eval(...