The Connection String Property

This property is used to provide ADO, and the OLE DB provider you are using, with the information required to connect to the data source. The connection string consists of a semicolon-delimited series of arguments in the form of "name=value;" pairs.

For the purposes of this chapter, the only ADO argument used is the Provider argument. The Provider argument tells ADO which OLE DB provider to use. All other arguments in connection strings presented in this chapter will be specific to the OLE DB provider being used. ADO will pass these arguments directly through to the provider. The following sample code demonstrates how to create a connection string to the Northwind database using the Access 2007 OLE DB provider:

objConn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _

"Data Source=C:\Files\Northwind 2007.accdb"

The only argument specific to ADO in the connection string is the Provider argument. All other arguments are passed directly through to the specified OLE DB provider. If a different provider were being used, the arguments would be different as well. You will see this when you begin to connect to various data sources in the example sections. The Provider argument to the connection string is optional. If no provider is specified, ADO uses the OLE DB provider for ODBC by default.

0 0

Responses

Post a comment