Application Architecture (3 Tire)

Posted by Bhaumik | 5:44 AM | 0 comments »

Database layer:

The database layer contains the tables, views and stored procedures which deals with the database. Usually this layer is created before making the other layers. Database layer is also the most important layer in the application architecture that's why most of the time is spent making the database layer solid so, the pillars of the application are strong and scalable.

2) Business logic layer:

Business logic layer contains the logic of the application. Like the database layer this layer is not exposed to the users directly but a user interface is provided to do so.

3) Presentation layer:

The presentation layer is what the user actually sees. The html pages with some animation, the textboxes to take input and message boxes to alarm the user of the operation of his action. Presentation layer must be developed in such a way that it can be changed without doing any changes to the business or the database layer. This means that the presentation layer must be independent of the database and the business layers. Also the presentation layer should be made in such a way that changing the presentation to the user will take less time and effort.

Tips about the database layer:

1) Database layer as I pointed out earlier consists of a database, stored procedures and tables etc. Its always good to use stored procedures instead of Ad-Hoc queries. Ad-Hoc queries have the danger of SQL Injection Stored procedures on the other hand are more fast to execute and gives the performance boost. Since those procedures used often are executed from the cache.

2) It's very important that you normalize the database design. You should carefully map out the one-one, one-many, many-many relationships. If normalization of the database is not handled carefully at the right time it can destroy the whole application and you may have to start from scratch.


Tips about the Business layer:

Business layer is where all the cool stuff happens. Usually for each subject (noun) in our specification we make a class for it. Suppose we are making an application where users and sends emails and receive messages depending on if their email is sent or not.

Some users tends to keep all the business logic in the presentation layer. This approach is very dangerous since user has a direct interaction with the business logic and it becomes easily hackable. That's why business logic is always kept in the class libraries this approach makes the separation of the user interaction with business logic and also makes the libraries portable so, it can be used by some other same type of application.

Sometimes its also a good idea to map the class fields to the database column names. Suppose our application stored articles so, our mapping class will look something like this:

public class ArticleDetails
{

public string Title;
public
string Url;
public
string Description;

}

Data Access Application Block:

I also explicitly use Microsoft.NET Data Access Application Block. Application Blocks makes the code simpler to understand and modify. Another good reason to use the application block is that it makes the code more readable if many coders are using the same block instead you find yourself reading every line of code written by the developer and trying to understand his coding style of accessing the database.

Messages Class:


Sometimes you want to print a message "Data has been successfully entered" if the transaction was successful and "Data not entered" when, the transaction was a failure.

Most of the developers perform this task by simply adding the if-else block in the presentation layer.

bool isDataInserted = code.AddCodeSample(txtTitle,txtDescription);

if(isDataInserted)
{

// Data inserted successfully

}
else

{

// Data not inserted

}


its a good idea to make a class whose main purpose is to return messages. You can call this class DBMessages.

// message returned after the insert operation

public static string InsertMessages(bool isAdded)
{

if(isAdded)
{

return "Inserted";

}
else

{

return "Not Inserted";

}

}

// message returned after the Update Operation

public static string UpdateMessages(bool isUpdated)
{

if(isUpdated)
{

return "Updated";

}
else

{

return "Not Updated";

}

}

As you see now you only have to write a single line of code to get the message. Here lblMessage is a label control.

lblMessage.Text = DBMessages.InsertMessages(isAdded);

Using this approach you can also modify your message in one place and it will be changed everywhere.

Tips for the Presentation Layer:

Presentation layer design should always be consistent since this layer will be the one that will change often. Consistent design can come in the form of the Cascading Style Sheets and User Controls. By using Cascading Style Sheets your page has a consistent look and feel. A simple change in the Cascading Style Sheet will bring changes to all the pages without even touching them.

User controls is another way for making sections that are easily changed. If on the other hand if they are not marked as a user controls we will have to go to each page and manually change it which, is a pain.

ASP.NET 3.5 and Visual Studio 2008

Posted by Bhaumik | 10:00 PM | 0 comments »

ASP.NET 3.5 and Visual Studio 2008 bring great new functionality around Web development and design that makes building standards based, next generation Web sites easier than ever. From the inclusion of ASP.NET AJAX into the runtime, to new controls, the new LINQ data capabilities, to improved support for CSS, JavaScript and others, Web development has taken a significant step forward.

ASP.NET AJAX

With ASP.NET AJAX, developers can quickly create pages with sophisticated, responsive user interfaces and more efficient client-server communication by simply adding a few server controls to their pages. Previously an extension to the ASP.NET runtime, ASP.NET AJAX is now built into the platform and makes the complicated task of building cross-platform, standards based AJAX applications easy.

Just go through the below link.

http://www.asp.net/Downloads/essential

LINQ and other .NET Framework 3.5 Improvements

With the addition of Language Integrated Query (LINQ) in .NET Framework 3.5, the process of building SQL queries using error-prone string manipulation is a thing of the past. LINQ makes your relational data queries a first-class language construct in C# and Visual Basic, complete with compiler and Intellisense support. For Web applications, the ASP.NET LinqDataSource control allows you to easily use LINQ to filter, order and group data that can then be bound to any of the data visualization controls like the ListView and GridView controls. In addition, all the other improvements to .NET Framework 3.5, including the new HashSet collection, DateTime offset support, diagnostics, garbage collection, better thread lock support, and more, are all available to you in your ASP.NET applications.



WCF Support for RSS, JSON, POX and Partial Trust

With .NET Framework 3.5, Windows Communication Foundation (WCF) now supports building Web services that can be exposed using any number of the Internet standard protocols, such as SOAP, RSS, JSON, POX and more. Whether you are building an AJAX application that uses JSON, providing syndication of your data via RSS, or building a standard SOAP Web service, WCF makes it easy to create your endpoints, and now, with .NET Framework 3.5, supports building Web services in partial-trust situations like a typical shared-hosting environment.

New Web Design Interface

Visual Studio 2008 has incorporated a new Web designer that uses the design engine from Expression Web. Moving between design and source view is faster than ever and the new split view capability means you can edit the HTML source and simultaneously see the results on the page. Support for style sheets in separate files has been added as well as a CSS properties pane which clarifies the sometimes-complex hierarchy of cascading styles, so that it is easy to understand why an element looks the way it does. In addition Visual Studio 2008 has full WYSIWYG support for building and using ASP.NET Nested Master Pages which greatly improves the ability to build a Web site with a consistent look and feel.

JavaScript Debugging and Intellisense

In Visual Studio 2008, client-side JavaScript has now become a first-class citizen in regards to its debugging and Intellisense support. Not only does the Intellisense give standard JavaScript keyword support, but it will automatically infer variable types and provide method, property and event support from any number of included script files. Similarly, the JavaScript debugging support now allows for the deep Watch and Locals support in JavaScript that you are accustomed to having in other languages in Visual Studio. And despite the dynamic nature of a lot of JavaScript, you will always be able to visualize and step into the JavaScript code, no matter where it is generated from. This is especially convenient when building ASP.NET AJAX applications.

Multi-targeting Support

In previous versions of Visual Studio, you could only build projects that targeted a single version of the .NET Framework. With Visual Studio 2008, we have introduced the concept of Multi-targeting. Through a simple drop-down, you can decide if you want a project to target .NET Framework 2.0, 3.0 or 3.5. The builds, the Intellisense, the toolbox, etc. will all adjust to the feature set of the specific version of the .NET Framework which you choose. This allows you to take advantage of the new features in Visual Studio 2008, like the Web design interface, and the improved JavaScript support, and still build your projects for their current runtime version.


ASP.NET Architecture

Posted by Bhaumik | 5:34 AM | 0 comments »

ASP.NET uses ISAPI to run on the Internet Information Server (IIS) in Windows 2000 Server. Not only does IIS host ASP.NET but the ISAPI filter mechanism also allows both ASP and ASP.NET to coexist on the same IIS server. (IIS can direct a *.asp page to ASP and a *.aspx page to ASP.NET.)

The configuration of ASP.NET is managed by information stored in XML-format in a configuration file (Web.Config).

The cache allows for improved performance of ASP.NET, as the most commonly requested pages would be served from the ASP.NET cache.

State management services for ASP.NET are provided by the ASP.NET state service.

The .NET Framework provides the Common Language Runtime (CLR), which compiles and manages the execution of ASP.NET code, and the class libraries, which offer prebuilt programmatic functionality for Web Forms, XML support, and exception handling.

ADO.NET provides ASP.NET with connections to databases.


ADO .NET

Posted by Bhaumik | 10:30 PM | 0 comments »

Most applications need data access at one point of time making it a crucial component when working with applications. Data access is making the application interact with a database, where all the data is stored. Different applications have different requirements for database access. VB .NET uses ADO .NET (Active X Data Object) as it's data access and manipulation protocol which also enables us to work with data on the Internet.Let's take a look why ADO .NET came into picture replacing ADO.


Evolution of ADO.NET

The first data access model, DAO (data access model) was created for local databases with the built-in Jet engine which had performance and functionality issues. Next came RDO (Remote Data Object) and ADO (Active Data Object) which were designed for Client Server architectures but soon ADO took over RDO. ADO was a good architecture but as the language changes so is the technology. With ADO, all the data is contained in a recordset object which had problems when implemented on the network and penetrating firewalls. ADO was a connected data access, which means that when a connection to the database is established the connection remains open until the application is closed. Leaving the connection open for the lifetime of the application raises concerns about database security and network traffic. Also, as databases are becoming increasingly important and as they are serving more people, a connected data access model makes us think about its productivity. For example, an application with connected data access may do well when connected to two clients, the same may do poorly when connected to 10 and might be unusable when connected to 100 or more. Also, open database connections use system resources to a maximum extent making the system performance less effective.

Why ADO.NET?

To cope up with some of the problems mentioned above, ADO .NET came into existence. ADO .NET addresses the above mentioned problems by maintaining a disconnected database access model which means, when an application interacts with the database, the connection is opened to serve the request of the application and is closed as soon as the request is completed. Likewise, if a database is Updated, the connection is opened long enough to complete the Update operation and is closed. By keeping connections open for only a minimum period of time, ADO .NET conserves system resources and provides maximum security for databases and also has less impact on system performance. Also, ADO .NET when interacting with the database uses XML and converts all the data into XML format for database related operations making them more efficient.


The ADO.NET Data Architecture

Data Access in ADO.NET relies on two components: DataSet and Data Provider.

DataSet

The dataset is a disconnected, in-memory representation of data. It can be considered as a local copy of the relevant portions of the database. The DataSet is persisted in memory and the data in it can be manipulated and updated independent of the database. When the use of this DataSet is finished, changes can be made back to the central database for updating. The data in DataSet can be loaded from any valid data source like Microsoft SQL server database, an Oracle database or from a Microsoft Access database.

Data Provider

The Data Provider is responsible for providing and maintaining the connection to the database. A DataProvider is a set of related components that work together to provide data in an efficient and performance driven manner. The .NET Framework currently comes with two DataProviders: the SQL Data Provider which is designed only to work with Microsoft's SQL Server 7.0 or later and the OleDb DataProvider which allows us to connect to other types of databases like Access and Oracle. Each DataProvider consists of the following component classes:

The Connection object which provides a connection to the database
The Command object which is used to execute a command
The DataReader object which provides a forward-only, read only, connected recordset
The DataAdapter object which populates a disconnected DataSet with data and performs update


Data access with ADO.NET can be summarized as follows:

A connection object establishes the connection for the application with the database. The command object provides direct execution of the command to the database. If the command returns more than a single value, the command object returns a DataReader to provide the data. Alternatively, the DataAdapter can be used to fill the Dataset object. The database can be updated using the command object or the DataAdapter.





Component classes that make up the Data Providers

The Connection Object

The Connection object creates the connection to the database. Microsoft Visual Studio .NET provides two types of Connection classes: the SqlConnection object, which is designed specifically to connect to Microsoft SQL Server 7.0 or later, and the OleDbConnection object, which can provide connections to a wide range of database types like Microsoft Access and Oracle. The Connection object contains all of the information required to open a connection to the database.

The Command Object

The Command object is represented by two corresponding classes: SqlCommand and OleDbCommand. Command objects are used to execute commands to a database across a data connection. The Command objects can be used to execute stored procedures on the database, SQL commands, or return complete tables directly. Command objects provide three methods that are used to execute commands on the database:

ExecuteNonQuery: Executes commands that have no return values such as INSERT, UPDATE or DELETE
ExecuteScalar: Returns a single value from a database query
ExecuteReader: Returns a result set by way of a DataReader object


The DataReader Object

The DataReader object provides a forward-only, read-only, connected stream recordset from a database. Unlike other components of the Data Provider, DataReader objects cannot be directly instantiated. Rather, the DataReader is returned as the result of the Command object's ExecuteReader method. The SqlCommand.ExecuteReader method returns a SqlDataReader object, and the OleDbCommand.ExecuteReader method returns an OleDbDataReader object. The DataReader can provide rows of data directly to application logic when you do not need to keep the data cached in memory. Because only one row is in memory at a time, the DataReader provides the lowest overhead in terms of system performance but requires the exclusive use of an open Connection object for the lifetime of the DataReader.

The DataAdapter Object

The DataAdapter is the class at the core of ADO .NET's disconnected data access. It is essentially the middleman facilitating all communication between the database and a DataSet. The DataAdapter is used either to fill a DataTable or DataSet with data from the database with it's Fill method. After the memory-resident data has been manipulated, the DataAdapter can commit the changes to the database by calling the Update method. The DataAdapter provides four properties that represent database commands:

SelectCommand
InsertCommand
DeleteCommand
UpdateCommand

When the Update method is called, changes in the DataSet are copied back to the database and the appropriate InsertCommand, DeleteCommand, or UpdateCommand is executed.