Connecting to Different Databases Using ASP.NET 2.0
(Page 1 of 5 )
This is the second article in a series focusing on developing applications using ASP.NET 2.0 and the Data Access Application Block available in Microsoft's Enterprise Application Block Library for .NET 2.0. In this article, I shall introduce you to all the database classes existing in Microsoft's Enterprise Library 2.0 along with examples.
A downloadable file for this article is available
here.
If you are new to Microsoft application blocks, I strongly suggest you refer to my first article in this series titled “Developing ASP.NET 2.0 Applications with Microsoft Data Access Application Block.” It gives a solid foundation for beginners.
Database classes included in Microsoft Enterprise Library 2.0
The database classes are the main classes used to work with databases. The following are the classes included in Microsoft Enterprise Library 2.0.
- Database
- SqlDatabase
- OracleDatabase
- GenericDatabase
Let us start with the “Database” class. It is basically an abstract class. It cannot be directly instantiated. The following is the declaration for the database class.
Public MustInherit Class Database
Inherits System.Object
The above class is defined in the “Microsoft.Practices.EnterpriseLibrary.Data” namespace. You can also observe the keyword “MustInherit,” which confirms that it is an abstract class.
You can create new database classes by inheriting from the database class. That will give the entire functionality of the Database class to your customized classes and you can further enhance them according to your requirements. This is generally used when you want to deal with any other database not included in “Microsoft Enterprise Library 2.0” (ex: Sybase). If you wanted to use the Database class directly to work with your existing databases, you need to use another class, “DatabaseFactory,” to instantiate a “Database” object.
Let us deal with another declaration:
Public Class SqlDatabase
Inherits Microsoft.Practices.EnterpriseLibrary.Data.Database
You can observe that the class SqlDatabase gets inherited from the previous class Database. It is available in the “Microsoft.Practices.EntepriseLibrary.Data.Sql” namespace. It has the total functionality of the Database class and has been optimized (and enhanced) to work with Microsoft SQL Server databases. This class internally uses the Microsoft SQL Server .NET managed provider available through System.data.SqlClient.
Similarly, we have another database class, “OracleDatabase,” defined similarly to the above class. It is mainly used to optimize applications with only Oracle databases. It is placed in the “Microsoft.Practices.EnterpriseLibrary.Data.Oracle” namespace.
Finally, we have another database class, “GenericDatabase,” which again gets inherited from “database” class. This is generally used when you do not know to which database you are connecting to. It is placed in the “Microsoft.Practices.EnterpriseLibrary.Data” namespace.
Next: Connecting to Microsoft SQL Server database using the database class: source code >>
More ASP.NET Articles
More By Jagadish Chaterjee