An introduction to ADO.NET - The SQL Server and OLE DB data providers
(Page 3 of 4 )
All .NET data providers must include core classes for creating the four types of objects listed in the first table in figure 2-3. You’ve already learned the basic functions of the connection, command, and data adapter objects. In addition to these, you can use a data reader object to access the data in a database in a read-only, forward-only manner.
The second table in this figure lists the two data providers that come with the .NET Framework. The SQL Server data provider is designed to provide efficient access to a Microsoft SQL Server database. The OLE DB data provider is a generic data provider that can access any database that supports the industry standard OLE DB interface, such as Oracle or MySQL. Although you can use the OLE DB data provider to access a SQL Server database, you shouldn’t do that unless you plan on migrating the data to another database since the SQL Server data provider is optimized for accessing SQL Server data.
In addition to the .NET data providers, you should also know that several database vendors have developed .NET data providers that are optimized for use with their databases. For example, .NET data providers are available for the popular MySQL database as well as for Oracle and SQL Anywhere. Before you develop an application using the OLE DB provider, then, you should check with your database vendor to see if a specialized .NET data provider is available.
The third table in this figure lists the names of the classes you use to create objects using the SQL Server and OLE DB providers. Notice that like the components you saw in the Toolbox in figure 2-2, all of the SQL Server classes are prefixed with “Sql” and all of the OLE DB classes are prefixed with “OleDb.” That way, it’s easy to tell which data provider you’re using in your applications.
When you develop a Visual Basic application that uses ADO.NET, you may want to add an Imports statement for the namespace that contains the data provider classes at the beginning of each source file that uses those classes. These namespaces are listed in the second table in this figure. If you include an Imports statement, you can then use the data provider classes without having to qualify them with the name of the namespace. The code shown in this figure illustrates how this works.
Now that you’re familiar with the core classes of the two .NET data providers, the next two topics will describe the classes of the SQL Server data provider in more detail. You should realize, though, that the information presented in these topics applies to the classes of the OLE DB data provider as well. In later chapters, you’ll learn some of the differences between these classes.
Figure 2-3. The .NET data providers
.NET data provider core objects

Data providers included with the .NET framework

Class names for the SQL Server and OLE DB data providers

Code that uses qualification to identify the data provider namespace
Dim conPayables As New SqlClient.SqlConnection()
Code that uses an Imports statement to identify the data provider namespace
Imports System.Data.SqlClient
.
.
Dim conPayables As New SqlConnection()
Description - In addition to the core classes shown above, classes are provided for other functions such as passing parameters to commands or working with transactions.
- To use a .NET data provider in a program, you should add an Imports statement for the appropriate namespace at the beginning of the source file. Otherwise, you’ll have to qualify each class you refer to with the SqlClient or OleDb namespace since these namespaces aren’t included as references by default.
- Other .NET data providers are available to provide efficient access to non-Microsoft databases such as Oracle, MySQL, and SQL Anywhere.
Next: The SqlConnection class >>
More .NET Articles
More By Murach Publishing
|
This article is excerpted from chapter two of the book VB.NET Database: Database Programming with ADO.NET, written by Anne Prince and Doug Lowe (Murach Publishing; ISBN: 1890774197). Check it out today at your favorite bookstore. Buy this book now.
|
|