Read without ads and support Scribd by becoming a Scribd Premium Reader.
 
IntroductionDesigning N-Tier client/server architecture is no less complex than developing two-tier architecture, however the N-Tier architecture, produces a far more flexible andscalable client/server environment. In two-tier architecture, the client and the server are the only layers. In this model, both the presentation layer and the middle layer arehandled by the client. N-Tier architecture has a presentation layer and three separatelayers - a business logic layer and a data access logic layer and a database layer. Thenext section discusses each of these layers in detail.
Different Layers of an N-Tier application
In a typical N-Tier environment, the client implements the presentation logic (thinclient). The business logic and data access logic are implemented on an applicationserver(s) and the data resides on database server(s). N-tier architecture is typicallythus defined by the following layers:
Presentation Layer: This is a front-end component, which is responsible for  providing portable presentation logic. Since the client is freed of applicationlayer tasks, which eliminates the need for powerful client technology. The presentation logic layer consists of standard ASP.NET web forms, ASP pages,documents, and Windows Forms, etc. This layer works with the results/outputof the business logic layer and transforms the results into something usableand readable by the end user.
Business Logic Layer: Allows users to share and control business logic byisolating it from the other layers of the application. The business layer functions between the presentation layer and data access logic layers, sendingthe client's data requests to the database layer through the data access layer.
Data Access Logic Layer: Provides access to the database by executing a setof SQL statements or stored procedures. This is where you will write genericmethods to interface with your data. For example, you will write a method for creating and opening a SqlConnection object, create a SqlCommand object for executing a stored procedure, etc. As the name suggests, the data access logiclayer contains no business rules or data manipulation/transformation logic. Itis merely a reusable interface to the database.
Database Layer: Made up of a RDBMS database component such as SQLServer that provides the mechanism to store and retrieve data. Now that you have a general understanding of the different layers in a N-Tier application, let us move onto discuss the implementation of a N-Tier Web application.ImplementationIn this article, I will consider an example web site (that displays authors and author titles information) constructed using N-Tier principles and use the example Web siteto demonstrate the new features of ASP.NET 2.0 and SQL Server 2005. The sampleWeb site shown in this example is very simple and straightforward and will consist of only two pages: the first page will show the list of authors from the pubs database andthe second page will display the list of titles specific to a selected author.
 
Please note that this article is not aimed at providing an exhaustive coverage of theindividual features of ASP.NET 2.0, instead it only focuses on helping the readersunderstand the features of ASP.NET 2.0 and SQL Server 2005 that are essential to building a N-Tier web application.Architecture of the Example ApplicationThe following screenshot shows the different layers in the example application. It alsohighlights the important characteristics of the example application.Some of the important characteristics of the sample application are as follows:
The stored procedures in the SQL Server 2005 database are created using C#.The ability to create stored procedures in managed code enables complex business logic to be executed close to the database resulting in performanceimprovements. The compiled nature of the stored procedure also results inincreased performance.
The data access layer classes are generated using the new TableAdapter Configuration Wizard, which enables you to create data access layer classeswithout writing a single line of code.
ASP.NET Web forms in the user interface layer are generated using master  pages, providing a consistent look and feel for the entire application.
Web forms utilize ObjectDataSource control to directly bind the output of themiddle tier methods to data bound controls such as a GridView control.
Web forms also take advantage of caching of database contents to increase the performance and throughput of the web application. This is made possible by
 
the use of the database cache invalidation mechanism that can automaticallyremove specific items from the cache when the data in the database tablechanges.Implementation of the ApplicationI will discuss the implementation by discussing each of the above layers, starting withthe database layer.
Database Objects using Managed Code
One of the neat features of SQL Server 2005 is the integration with the .NET CLR.The integration of CLR with SQL Server extends the capability of SQL Server inseveral important ways. This integration enables developers to create database objectssuch as stored procedures, user defined functions, and triggers by using modernobject-oriented languages such as VB.NET and C#. In this article, I will demonstratehow to create the stored procedures using C#. Before looking at the code, let usunderstand the pros and cons of using managed language in the database tier to createserver side objects.
T-SQL Vs Managed Code
 Although T-SQL, the existing data access and manipulation language, is well suitedfor set-oriented data access operations, it also has limitations. It was designed morethan a decade ago and it is a procedural language rather than an object-orientedlanguage. The integration of the .NET CLR with SQL Server enables the developmentof stored procedures, user-defined functions, triggers, aggregates, and user-definedtypes using any of the .NET languages. This is enabled by the fact that the SQLServer engine hosts the CLR in-process. All managed code that executes in the server runs within the confines of the CLR. The managed code accesses the database usingADO.NET in conjunction with the new SQL Server Data Provider. Both Visual Basic.NET and C# are modern programming languages offering full support for arrays,structured exception handling, and collections. Developers can leverage CLR integration to write code that has more complex logic and is more suited for computation tasks using languages such as Visual Basic .NET and C#. Managed codeis better suited than Transact-SQL for number crunching and complicated executionlogic, and features extensive support for many complex tasks, including stringhandling and regular expressions. T-SQL is a better candidate in situations where thecode will mostly perform data access with little or no procedural logic. Even thoughthe example you are going to see in this article is best written using T-SQL, I will takethe managed code approach and show you how to leverage that feature.
Creating CLR Based Stored Procedures
 For the purposes of this example, create a new SQL Server Project using Visual C# asthe language of choice in Visual Studio 2005. Since you are creating a database project, you need to associate a data source with the project. At the time of creatingthe project, Visual Studio will automatically prompt you to either select an existingdatabase reference or add a new database reference. Choose pubs as the database.Once the project is created, select
Add Stored Procedure
from the
Project
menu.
Search History:
Searching...
Result 00 of 00
00 results for result for
  • p.
  • Notes
    Load more