In this post we will learn how to implement the three tier architecture in our application using Asp.Net c#. My previous post Highlight Asp.net gridview row color on mouseover using javascript and css
Explanation
Many interviews we faced the question whether you used 3-tier architecture in your application.Because it is mandatory to know the 3-tier architecture for developing a project. Three tier architecture is a separation of our application into multiple portion which is called as a layer.So we have to understand about the layer in 3-tier architecture.
Layer architecture vs Tier architecture
Layer architecture : Logical Separation of our application will be stored in the same server.
Tier architecture : Physical Separation of our application will be stored in multiple servers which will be communicated via web service or WCF services.
We may split our application into many layers which is called 'N' layered architecture. So the base for multiple layer architecture is 3-tier architecture. So before 3-tier architecture we have used two-tier architecture, which is having client - server request and response. We will keep the coding and design in same page and it is having lot of source code and we have confusion for analysing the coding and maintenance is very hard.
As mentioned in the above picture representation, While accessing a website through browser the first hit will be in the Presentation/ Application Layer. The request from Presentation/ Application Layer will be traversed to the Business Logic Layer. Then Business logic layer request traverse the request to Data Access Layer. Finally the Data Access Layer will do the communication with our SQL database and the transaction completion of the given request. The response from SQL database will reach the Data Access Layer , the Data access Layer traverse the response to Business Logic Layer. Finally the response will reach the presentation Layer. This is a vice versa request and response in 3-tier architecture.
Types of Layers in Project
1. Presentation/Application Layer.
2. Business Logic Layer.
3. Data Access Layer.
Presentation/Application Layer
Presentation Layer or Application Layer is the user interaction layer which is available for getting the inputs from the user. Asp.Net extention page (.aspx) which contains the web controls with design is called as presentation layer. This is a very important layer in a project, because even if you have complicated coding in your project but it won't be visible for an user. Attractive design is the highlight of a project to retain the user. Sometimes we search a topic in internet and a list of link will appear, we will be interest to watch only the pleasant and attractive design web sites.
Business Logic Layer
Business Logic Layer is the pillar of the project which will interact with the Presentation layer and Data access layer. Any business requirement coding will be handled in Business Logic Layer. Before traverse a request into Data access layer, this layer will validate, If validation is not through it will revert the request into presentation layer. Once the request is clear then it will traverse the request into data access layer and wait for the response of the given request.
Data Access Layer
Data Access Layer is mainly used to communicate with our database and proceed the request raised through business logic layer and revert the response to the Business logic layer. We will invoke the connection settings, SQL procedure and sql transaction queries in this layer.
3-tier architecture Advantages in Asp.Net Project
By practice keep the application and SQL in different server, because transaction request will hit in both places if it is hosted in a single server the response may get too slow if concurrent users access your website.
Project is splitted into multiple layers, we are easily to track the methods which are available in which layer pages.
Strong Object oriented programming knowledge will be easier for working on 3-tier architecture.
Without affecting presentation layer we could do the validation methods in Business layer. In Data layer stored procedure names modifications can be easily done.
Creating step by step three tier architecture example
Show the page view count in Asp.Net c# Application using 3-tier architecture.
Step 1: Create the SQL tables and stored procedures
-- Create a PageViewCount Table with count ID and Last visited date.
CREATE TABLE [dbo].[PageViewCount] (
[pvCountID] [int] NOT NULL,
[pvLastVisitedDate] [datetime] NULL
) ON [PRIMARY]
GO
--Create a Stored Procedure for Insert and update the PageViewCount Table
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE dbo.Proc_Insert_Update_PageViewCount
AS
BEGIN
SET NOCOUNT ON
DECLARE @PageViewCounts INT=1
IF EXISTS(select 'X' from PageViewCount)
BEGIN
UPDATE PageViewCount SET pvCountID +=@PageViewCounts,pvLastVisitedDate=GETDATE()
END
ELSE
BEGIN
INSERT INTO PageViewCount(pvCountID,pvLastVisitedDate) values(@PageViewCounts,GETDATE())
END
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
--Create a Stored Procedure for fetch the PageViewCount Table
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE dbo.Proc_Select_PageViewCount
AS
BEGIN
SET NOCOUNT ON
DECLARE @PageViewCounts INT=1
IF EXISTS(select 'X' from PageViewCount)
BEGIN
SELECT pvCountID,pvLastVisitedDate from PageViewCount
END
ELSE
BEGIN
SELECT 0,GETDATE()
END
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
Step 2: Create a sample application in Visual studio 2010 as shown below.
Step 3: Design the Page view count screen, with lables pageviewcount and lastvisited datetime
<div>
<table cellpadding="5" cellspacing="5" align="center" border="1">
<tr>
<td>
Total Page Views :
</td>
<td>
<asp:Label ID="lblPageViewCount" ForeColor="Red" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
Last Visited Time :
</td>
<td>
<asp:Label ID="lblLatVisitedDateTime" ForeColor="Red" runat="server"></asp:Label>
</td>
</tr>
</table>
</div>
Step 4: Add a new project as a class library through solution explorer as mentioned below.
Name the class library as BOFactory and DAEngine as shown below.
Step 5: We have to give reference of these projects
DAEngine-> reference in BOFactory-> reference in Application project
Step 6: Connection strings need to be added in web config file.
<connectionStrings>
<add name="Connection" connectionString="Data Source=XXXXX;Initial Catalog=DBName;User ID=UID;Password=XXXX" providerName="System.Data.SqlClient"/>
</connectionStrings>
Download the sample project
Output
My previous post Highlight Asp.net gridview row color on mouseover using javascript and css
Good Explanation : Let me show you one example which generally people wants to try on their own but they can't make it...
ReplyDeleteLogin Code with 3 Tier Architecture
==========================
Create Login Page with 3 Tier Architecture
Microsoft develops software called DOTNET. It is a software framework. DOTNET mainly runs on Microsoft windows. It is similar to Java. .Net is most preferred programming language among software developers all over the world. It is also considered as most trusted and effective platform to build high performing desktop or enterprise application.
ReplyDeleteThanks,
DOTNET Training in Chennai | DOTNET course in Chennai | DOTNET Training Institute in Chennai
Thanks for sharing this post with us it is a worth read.. Thanks for the tutorial, I been searching for this for a long time, At last reached to the got post. Thank you giving a information about Android Development
ReplyDeleteGraphic design course in chennai
Nice Blog.Thank you for Sharing.
ReplyDeletebrave technologies | campus events
This software has a set of predefined tools which first organize the problems on the basis of their difficulty and then it searches for the resources used for solving the problems. cheap Revit 2018
ReplyDeleteGreat blog., I got some data about asp.net really its so nice to read.. Thanks for sharing, kindly keep updating such a nice blog.. Software Testing Training in Chennai | Six Sigma Certification Training in Chennai | Selenium Training in Chennai
ReplyDeletethank you for such a great article with us. hope it will be much useful for us. please keep on updating..Web Designing Training Institute in Chennai | Web Designing Training Institute in Velachery.
ReplyDeletevery useful to us.i really like it
ReplyDeletepersonalrekrutierung
Impressive and useful article on ASP.NET. Thanks for sharing..
ReplyDeleteFinal Year Project Center in Chennai | IEEE Project Center in Chennai | Diploma Project Center in Chennai
Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
ReplyDeleteSelenium Training in Bangalore
Hi, your way of teaching about ASP..It's really helpful..thanks for sharing useful post..
ReplyDeleteMCSE Training in Chennai | Hardware and Networking Training in Chennai
Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
ReplyDeletewhite label website builder
mobile website builder
wow! great list, I also have a list for my blog. But your list was amazing, will use some of them. Thanks!
ReplyDeleteGood CorelDraw Training Institute in Chennai | Best Multimedia Training Institute in Velachery | Perfect CorelDraw Training Institute in Velachery
I believe that there would be great opportunities for those who are coming around this area. Please do keep updating on...
ReplyDeleteBest Online Software Training Institute | Asp.Net Training
thanks for sharing the information
ReplyDeleteWeb design and development Training Institute in Chennai | Web design and development Training Institute in Velachery
I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.
ReplyDeleteDot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery
I have been searching for a useful post like this on salesforce course details, it is highly helpful for me and I have a great experience with this Salesforce Training who are providing certification and job assistance. Best Salesforce training institute in Gurgaon
ReplyDeleteslot siteleri
ReplyDeletekralbet
betpark
tipobet
mobil ödeme bahis
betmatik
kibris bahis siteleri
poker siteleri
bonus veren siteler
HHN4
شركة عزل اسطح بخميس مشيط
ReplyDeletejQ2KycvyuQ