8.1. Connect to a Database


You need to open a connection to a database.


Create a connection object appropriate to the type of database to which you need to connect. Configure the connection object by setting its ConnectionString property. Open the connection by calling the connection object's Open method.

How It Works

The first step in database access is to open a connection to the database. All connection objects inherit from the MustInherit System.Data.Common.DbConnection class. This class implements the System.Data.IDbConnection interface. The DbConnection class represents a database connection, and each data provider includes a unique implementation. Here is the list of the implementations for the five standard data providers: ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.