Friday, January 18, 2013

ADO.NET Basics

ADO.NET relies on the functionality in a small set of core classes. You can divide these classes into two groups: those that are used to contain and manage data (such as DataSet, DataTable,DataRow, and DataRelation) and those that are used to connect to a specific data source (such as Connection, Command, and DataReader).

The data container classes are completely generic. No matter what data source you use, once you extract the data, it’s stored using the same data container: the specialized DataSet class. Think of the DataSet as playing the same role as a collection or an array—it’s a package for data. The difference is that the DataSet is customized for relational data, which means it understands concepts such as rows, columns, and table relationships natively. The second group of classes exists in several different flavors. Each set of data interaction classes is called an ADO.NET data provider. Data providers are customized so that each one uses the best-performing way of interacting with its data source. For example, the SQL Server data provider is designed to work with SQL Server 7 or later. Internally, it uses SQL Server’s TDS (tabular data stream) protocol for communicating, thus guaranteeing the best possible performance. If you’re using Oracle, you’ll need to use the Oracle provider classes instead.

It’s important to understand that you can use any data provider in almost the same way, with almost the same code. The provider classes derive from the same base classes, implement the same interfaces, and expose the same set of methods and properties. In some cases, a data provider object will provide custom functionality that’s available only with certain data sources, such as SQL Server’s ability to perform XML queries. However, the basic members used for retrieving and modifying data are identical. NET includes the following four providers:

• SQL Server provider: Provides optimized access to a SQL Server database (version 7.0 or later)
• OLE DB provider: Provides access to any data source that has an OLE DB driver
• Oracle provider: Provides optimized access to an Oracle database (version 8i or later)
• ODBC provider: Provides access to any data source that has an ODBC (Open Database Connectivity) driver

In addition, third-party developers and database vendors have released their own ADO.NET providers, which follow the same conventions and can be used in the same way as those that are included with the .NET Framework. When choosing a provider, you should first try to find one that’s customized for your data source. If you can’t find a suitable provider, you can use the OLE DB provider, as long as you have an OLE DB driver for your data source. The OLE DB technology has been around for many years as part of ADO, so most data sources provide an OLE DB driver (including SQL Server, Oracle, Access, MySQL, and many more). In the rare situation that you can’t find a full provider or an OLE DB driver, you can fall back on the ODBC provider, which works in conjunction with an ODBC driver.

No comments:
Write comments
Recommended Posts × +