Database Independent Development using ASP.NET 2.0
(Page 1 of 6 )
This article shows you how to develop database independent applications using ASP.NET 2.0. I shall also show you how to develop a simple database independent data access layer using ADO.NET 2.0.
A downloadable file for this article is available
here.
The entire solution (source code) for this article is available as a free download (in the form of a zip). All the applications in this series have been developed using Microsoft Visual Studio 2005 Professional Edition on Microsoft Windows Server 2003 Standard Edition together with Microsoft SQL Server 2005 Express Edition and Oracle 10g Express editions as the database. I didn't really test any of the code in any other tools/IDEs/servers/editions/versions. If you have any problems, please feel free to post in the discussion area.
Provider independent model in ADO.NET 2.0
ADO.NET internally works with .NET data providers (or .NET data bridge providers) to connect to and access data from different kinds of data sources (including databases). The same data provider model existing in ADO.NET 1.1 is further enhanced in ADO.NET 2.0 (with a few factory classes) to leverage the flexibility of developing database independent applications.
The purpose of a factory class is to provide an interface for creating families of related objects, with or without specifying their concrete (method implementation) classes. If the factory class is created without one or more implementations of methods, we call it an abstract factory class.
The provider-independent programming model in ADO.NET 2.0 revolves around the classes in the System.Data.Common namespace. There are mainly two new factory classes that implement the provider-independent model (with the same namespace):
- DbProviderFactories
- DbProviderFactory
The DbProviderFactories class is mainly used to enumerate all .NET data providers installed on your machine. Using the same class, we can also create instances related to a specific provider (to access databases specific to that provider). These instances are nothing but the objects of the DbProviderFactory class.
Using the DbProviderFactory class, we can create Connection, Command, DataAdapter and other objects. These objects will be provider specific (like SQLConnection, OracleConnection, ODBCConnection etc.), but will be returned into a "commons" like parent classes called DBConnection, DBCommand, DBDataAdapter etc. which are available as part of System.Data.Common namespace.
The upcoming sections will show you how to develop a database independent data access layer using ADO.NET 2.0
Next: Developing a common class which works with Factories: source code >>
More ASP.NET Articles
More By Jagadish Chaterjee