The Connection Object

The Connection object is what provides the pipeline between your application and the data source you want to access. Like the other top-level ADO objects, the Connection object is extremely flexible. In some cases, this may be the only object you need to use. Simple commands can easily be executed directly through a Connection object. In other cases, you may not need to create a Connection object at all. The Command and Recordset objects can create a Connection object automatically if they need one.

Constructing and tearing down a data source connection can be a time-consuming process. If you will be executing multiple SQL statements over the course of your application, you should create a publicly scoped Connection object variable and use it for each query. This allows you to take advantage of connection pooling.

Connection pooling is a feature provided by ADO that will preserve and reuse connections to the data source rather than creating new connections for each query, which would be a waste of resources. Connections can be reused for different queries as long as their connection strings are identical. This is typically the case in Excel applications, so I recommend taking advantage of it.

0 0

Post a comment