ADO Connection Object



techstore
 LQ Net Home






















Creating a Connection Object

printpage    Printer Friendly Page

The ADO Connection Object provides a connection to a data store.


A connection object can be created using a Data Source Name [DSN]
or by specify the data store (data source) and data provider.

Dim cn As ADODB.Connection
Set cn = New ADODB.Connection


Set the connection to a DSN data provider

Dim cn As ADODB.Connection
Set cn = New ADODB.Connection

cn.Open "DSN=Products"
       OR
cn.ConnectionString = "DSN=Products"
cn.Open


If DSN isn't used, a Connection String will define the data source and
   data provider.

OLE DB Connection String for an Access Database

Dim cn As ADODB.Connection
Set cn = New ADODB.Connection

cn.ConnectionString = "Microsoft.Jet.OLEDB.4.0:
Data Source=C:\QSPR\Sales.mdb"

cn.Open


You can also build the connection string in the Open method.

Dim cn As ADODB.Connection
Set cn = New ADODB.Connection

cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\QSPR\Sales.mdb;"



The Connection Mode defines the read/write permissions.

cn.Mode = adModeReadWrite


adModeRead Read-only permission.
adModeWrite Write-only permission.
adModeReadWrite Read and write permission.
adModeUnknown Permissions not defined.


Dim cn As ADODB.Connection
Set cn = New ADODB.Connection

cn.Mode = adModeReadWrite
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\QSPR\Sales.mdb;"


See more connection string examples


To see the full connection string after opening:
Debug.Print "Full connection string: " + cn.ConnectionString













   Today's News





Office Depot, Inc

Tech Depot - An Office Depot Co.



Overstock.com, Inc.

























Copyright © 2006-2008, LQ Systems,Inc. All rights reserved.