Chapter 10: Database Access


Overview

In the Microsoft .NET Framework, access to a wide variety of data sources is enabled through a group of classes collectively named Microsoft ADO.NET. Each type of data source is supported through the provision of a data provider. Each data provider contains a set of classes that not only implement a standard set of interfaces, but also provide functionality unique to the data source they support. These classes include representations of connections, commands, properties, data adapters, and data readers through which you interact with a data source. Table 10.1 lists the data providers included as standard with the .NET Framework.

Table 10.1: .NET Framework Data Provider Implementations

Data Provider

Description

.NET Framework Data Provider for ODBC

Provides connectivity to any data source that implements an ODBC interface; this includes Microsoft SQL Server, Oracle, and Microsoft Access databases. Data provider classes are contained in the System.Data.Odbc namespace and have the prefix Odbc .

.NET Framework Data Provider for OLE DB

Provides connectivity to any data source that implements an OLE DB interface; this includes Microsoft SQL Server, MSDE, Oracle, and Jet databases. Data provider classes are contained in the System.Data.OleDb namespace and have the prefix OleDb .

.NET Framework Data Provider for Oracle

Provides optimized connectivity to Oracle databases. Data provider classes are contained in the System.Data.OracleClient namespace and have the prefix Oracle .

.NET Framework Data Provider for SQL Server

Provides optimized connectivity to Microsoft SQL Server version 7 and later (including MSDE) by communicating directly with the SQL Server without the need to use ODBC or OLE DB. Data provider classes are contained in the System.Data.SqlClient namespace and have the prefix Sql .

.NET Compact Framework Data Provider for SQL Server CE

Provides connectivity to Microsoft SQL Server CE. Data provider classes are contained in the System.Data.SqlServerCe namespace and have the prefix SqlCe .

This chapter describes some of the most commonly used aspects of ADO.NET. However, ADO.NET is an extensive subsection of the .NET Framework class library and includes a great deal of advanced functionality. For a comprehensive coverage of ADO.NET, you should read David Sceppa's excellent book Microsoft ADO.NET Core Reference (Microsoft Press, 2002). The recipes in this chapter describe the following:

  • How to create, configure, open , and close database connections (recipe 10.1)

  • How to use connection pooling to improve the performance and scalability of applications that use database connections (recipe 10.2)

  • How to execute SQL commands and stored procedures and how to use parameters to improve their flexibility (recipes 10.3 and 10.4)

  • How to process the results returned by database queries (recipes 10.5 and 10.6)

  • How to discover all instances of SQL Server available on a network (recipe 10.7)

    Note  

    The recipes in this chapter use the Northwind sample database provided by Microsoft to demonstrate the techniques discussed.




C# Programmer[ap]s Cookbook
C# Programmer[ap]s Cookbook
ISBN: 735619301
EAN: N/A
Year: 2006
Pages: 266

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net