Click here to Skip to main content
Licence 
First Posted 27 Aug 2004
Views 217,334
Downloads 2,826
Bookmarked 83 times

Microsoft Application Block for Data Access in .NET

By Sekhar Lanka | 5 Sep 2004
This article gives an overview of Microsoft Application Block for Data Access, its advantages and specifies its usage in a .NET application.
 
Part of The SQL Zone sponsored by
See Also
15 votes, 34.1%
1
8 votes, 18.2%
2
4 votes, 9.1%
3
7 votes, 15.9%
4
10 votes, 22.7%
5
2.59/5 - 44 votes
μ 2.63, σa 2.79 [?]

Introduction

Summary:

Microsoft has developed and released Application Blocks for Data Access and Exception Management for using in .NET applications. These application blocks provide the .NET developer not only the ready to use code inside the application, but also the code which was built by encapsulating the best practices by Microsoft.

In this discussion we are going to examine the following:

  • What are the advantages of Data Access Application Block?
  • How to install the Data Access Application Block?
  • Create a sample .NET application using the Data Access Application Block.

Advantages of Data Access Application Block

Microsoft has developed this wrapper on top of the ADO.NET layer by encapsulating the performance and memory management related best practices for Microsoft SQL Server. So we need not worry about the data access performance and memory leaks.

This comes as a single assembly with a class consisting of useful methods which serve all kinds data access requirements. By using these simple calls in our code, we can reduce the amount of custom code we actually write in our conventional applications. Moreover we can also skip the over head of testing and maintenance of our custom code.

Microsoft provides the source code files, along with the Quick start samples and documentation. We can use the source code as it is or we can even customize as per our application needs.

Installing the Data Access Application Block

This is a free software and you can download it from here.

The current version of this block is 2.0. And we need to have Visual Studio. NET installed on the target machine.

Your installation should create an entry in the Start > Programs > menu called “Microsoft Application Blocks for .NET”, where it will show links to source code and samples.

Sample screenshot

Fig 1: After installing the Application Block.

Select the Data Access Application Block option by navigating to the path shown in the figure. It then opens the solution in the VS.NET IDE.

Sample screenshot

Fig 2: Open the Data Access Application Block solution in the IDE.

Click on the SQLHelper.cs file to look inside the code. It creates a namespace with the name Microsoft.ApplicationBlocks.Data with two sealed classes SqlHelper and SqlHelperParameterCache created inside that.

Now right click on the project name and click Build. Now you should see the assembly created at the following path:

C:\Program Files\Microsoft Application Blocks for .NET\Data Access v2\Code\CS\Microsoft.ApplicationBlocks.Data\bin\Debug

So we have built the Data Access block assembly, now we create a Web Application in which we refer this assembly. In our web application, we use a simple web form to connect to SQL Server 2000 and access the data from the database.

Create a sample .NET application using Data Access Block.

Step 1: Select File > New > Project from the file menu, select the ASP.NET Web Application and enter the project name and path accordingly.

Sample screenshot

Fig 3: Creating a sample web application.

Step 2: Now we add the Data Access Block to our project. To do this, right click on the references node and click Add Reference. Click on the Browse and select the Microsoft.ApplicationBlocks.Data.dll and click Ok button.

Sample screenshot

Fig 4: Adding the Data Access Block reference.

Step 3: Open the WebForm1 and drag a datagrid from the toolbox onto it.

Sample screenshot

Fig 5: Adding the datagrid to the WebForm1.

Step 4: Add the line for using the Data Access Block assembly.

Sample screenshot

Fig 6: Using Microsoft.ApplicationBlocks.Data namespace.

Step 5: Add the following code in the Page_Load event procedure.

This code creates a connection to the SQL Server database.

We have used the ExecuteDataset static method of the SqlHelper class to fetch the top 10 records from Employees table.

Sample screenshot

Fig 7: Call SqlHelper.ExecuteDataset method

In the above code, I have used my own credentials for connecting SQL Server. Please change those accordingly.

Step 6: Run the WebForm1.aspx page in the browser to see the output.

Sample screenshot

Fig 8: Result displayed in WebForm1.aspx

Conclusion

In this discussion I have tried my best in exploring the Data Access Block with a simple example. Try to explore other useful methods available in SqlHelper which serve for variety of data access purposes. For wide information on this topic, visit microsoft.com.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Sekhar Lanka

Web Developer

United States United States

Member
His areas of interests are C#, ASP.NET, SQL Server and UML.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Question???? PinmemberRavindra_Parcha18:10 13 Jan '12  
GeneralUm PinmemberSpeedisavirus9:36 16 Jun '11  
Questionfor Oracle ??? Pinmemberalhambra-eidos8:30 20 Oct '09  
GeneralArrgggghhhhhhhh PinmemberPete O'Hanlon0:58 5 Nov '07  
GeneralHi Pinmembermezzo0:28 5 Nov '07  
GeneralHi PinmemberRamesh Duppati21:49 7 Sep '06  
GeneralThis is terrible Pinmembermarcroach9:59 27 Mar '06  
GeneralPuur PinsussAnonymous3:33 7 Oct '05  
GeneralRe: Puur PinsussMCDBA3:34 7 Oct '05  
GeneralBuild Error Pinmembernorm22:44 21 Jul '05  
GeneralArticle PinmemberJonathan Bays18:11 8 Nov '04  
GeneralRe: Article Pinmemberkiran133110:02 23 Mar '06  
GeneralVery misleading PinmemberDiBrun23:55 15 Sep '04  
GeneralRe: Very misleading Pinmemberfadee1:20 16 Sep '04  
Generalyup, good job Pinmembernorm22:19 21 Jul '05  
GeneralRe: Very misleading PinsussAnonymous11:03 23 May '05  
General1. With/Without App Block + 2. NHibernate Pinmembernorm22:22 21 Jul '05  
GeneralRe: Very misleading Pinmembereliakaris15:40 1 Nov '05  
GeneralRe: Very misleading PinmemberGhayas Ur Rehman8:12 16 Feb '09  
QuestionDemo project ?!? PinmemberColin Angus Mackay6:05 6 Sep '04  
What demo project - It is a 1Mb word document.
 
You have received some good comments on improving the quality of this article. It would make the article much more useful if you followed them.
 
1. Screenshots cropped to the relevant area - and not squashed up. We want to actually see what is in them, not line the pockets of our optitians.
2. Text code snippets rather than screenshots.
3. Making the demo project a zip of downloadable source code
4. Mark the article as for Beginners.
 
I really like the tutorial style you've taken, and with a little work this could be a most excellent article.
 

"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
 
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!


GeneralNot good PinmemberAlsius5:26 6 Sep '04  
GeneralRe: Not good PinmemberSekhar Lanka21:30 6 Sep '04  
GeneralModification Pinmemberm a y s a m23:30 28 Aug '04  
GeneralRe: Modification Pinmemberfabulous8:52 29 Aug '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120210.1 | Last Updated 6 Sep 2004
Article Copyright 2004 by Sekhar Lanka
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid