Database Reference
In-Depth Information
C H A P T E R 12
Making Connections
Before you can do anything useful with a database, you need to establish a session with the database
server. You do this with an object called a connection, which is an instance of a class that implements the
System.Data.IDbConnection interface for a specific data provider. In this chapter, you'll use various data
providers to establish connections and look at problems that may arise and how to solve them. In this
chapter, we'll cover the following:
Introducing data provider connection classes
Connecting to SQL Server with SqlConnection
Improving your use of connection objects
Connecting to SQL Server with OleDbConnection
Introducing the Data Provider Connection Classes
As you saw in Chapter 10, each data provider has its own namespace. Each has a connection class that
implements the System.Data.IDbConnection interface. Table 12-1 summarizes the data providers
supplied by Microsoft.
Table 12-1. Data Provider Namespaces and Connection Classes
Data Provider
Namespace
Connection Class
System.Data.Odbc
OdbcConnection
ODBC
System.Data.OleDb
OleDbConnection
OLE DB
System.Data.OracleClient
OracleConnection
Oracle
System.Data.SqlClient
SqlConnection
SQL Server
System.Data.SqlServerCe
SqlCeConnection
SQL Server CE
As you can see, the names follow a convention, using Connection prefixed by an identifier for the
data provider. Since all connection classes implement System.Data.IDbConnection , the use of each one is
similar. Each has additional members that provide methods specific to a particular database.
 
Search WWH ::




Custom Search