Help Center

CAdoConnection.ConnectionStringproperty

Indicates the information used to establish a connection to a data source.

DatabasespropertyCAdoConnection.incdocumented

Syntax

PROPERTY ConnectionString () AS DWSTRING
PROPERTY ConnectionString (BYREF wszConStr AS WSTRING)

Parameters

NameDescription
wszConStrThe connection string.

Return value

The connection string.

Description

Indicates the information used to establish a connection to a data source.

Remarks

Use the ConnectionString property to specify a data source by passing a detailed connection string containing a series of argument = value statements separated by semicolons.

ADO supports five arguments for the ConnectionString property; any other arguments pass directly to the provider without any processing by ADO. The arguments ADO supports are as follows.

After you set the ConnectionString property and open the Connection object, the provider may alter the contents of the property, for example, by mapping the ADO-defined argument names to their provider equivalents.

The ConnectionString property automatically inherits the value used for the ConnectionString argument of the Open method, so you can override the current ConnectionString property during the Open method call.

Because the File Name argument causes ADO to load the associated provider, you cannot pass both the Provider and File Name arguments.

The ConnectionString property is read/write when the connection is closed and read-only when it is open.

Duplicates of an argument in the ConnectionString property are ignored. The last instance of any argument is used.

Examples

pConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=biblio.mdb" pConnection.Open

DIM dwsConStr AS DWSTRING = pConnection.ConnectionString

#include once "AfxNova/CADODB.inc" USING AfxNova

' // === Open the connection DIM pConnection AS CAdoConnection pConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=biblio.mdb" pConnection.Open

' // === Open the recordset DIM pRecordset AS CAdoRecordset pRecordset.Open("SELECT * FROM Authors", pConnection, adOpenKeyset, adLockOptimistic, adCmdText)

' // === Parse the recordset ' // While not at the end of the recordset... DO WHILE NOT pRecordset.EOF ' // Get the content of the "Author" column PRINT pRecordset.Collect("Author") ' // Fetch the next row IF pRecordset.MoveNext <> S_OK THEN EXIT DO LOOP

' // === Close the recordset and the connection ' // If you don't close them, they will be closed when the application ends pRecordset.Close pConnection.Close

Reference

  • Include file CAdoConnection.inc
  • Defined in AfxNova/CAdoConnection.inc:205
  • Documented in Databases/ADO Classes/CAdoConnection Class.md
  • Topic: CAdoConnection Class