Export (0) Print
Expand All
3 out of 4 rated this helpful - Rate this topic

Step 1 - The Connection Object

Visual Studio 6.0

The Connection object allows us to establish connection sessions with data sources. In other words, the connection represents a physical connection to a data source. The connection we set up provides a mechanism for initializing and establishing the connection. Once the connection object is created we can use its methods and properties to use the data source (in this case the database) that we have connected to. We will also use the connection for executing queries and using transactions (we'll talk about these in detail later). The underlying OLE DB provider is used for connecting to the data source.

Let's briefly summarize the methods of the connection object:

Connection Object Methods Description
Open Opens a new connection to a data source
Close Closes a connection as well as any dependant objects
Execute Executes a query, typically an SQL statement
BeginTrans Starts a new transaction
CommitTrans Commits changes made during the transaction
RollBackTrans Cancels any changes done during a transaction

And here are the connection object's properties:

Connection Object Properties Description
ConnectionString Contains the necessary information to establish a connection
ConnectionTimeOut Determines how long to wait to establish a connection.
CommandTimeOut Determines how long to wait while executing a command.
State Indicates if a connection is open.
Provider Indicates the name of the provider
Version Indicates the ADO version.
CursorLocation Sets/returns the location of the cursor engine.

As we mentioned, the connection object allows us to establish sessions with data sources. But remember, behind the scenes the underlying OLE DB provider is actually used for connecting to the data source. That is how the magic is accomplished.

We program to the ADO interface. But remember when we selected the OLE DB provider when we selected "Build…" next to the Connection String option? It is the OLE DB provider that knows how to take commands from ADO and translate them into language that the specific data source will understand. Makes sense now, doesn't it? And as more and more suppliers create OLE DB providers for their data sources, ADO will take over the world.

© 1998 by Wrox Press. All rights reserved.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.