Returns or sets a value that provides information about the source of an open rdoConnection. The Connect property contains the ODBC connect string. This property is always readable, but cannot be changed after the connection is established.
Syntax
object.Connect [= value]
The Connect property syntax has these parts:
Part | Description |
object | An object expression that evaluates to an object in the Applies To list. |
value | A string expression as described in Remarks. (Data type is String) |
Settings
The Connect property return value is a String expression composed of zero or more parameters separated by semicolons, as described in Remarks.
Remarks
When used with the rdoQuery or rdoConnection objects, this property is read-only unless created as a stand-alone object when it is read-write until the connection is established. The Connect property becomes read-write when the rdoConnection object is closed. When used with the RemoteData control, this property is read-write.
The Connect property is used to pass additional information to and from the ODBC driver manager to establish a connection with a data source. The Connect property holds the ODBC connect string which is also used as an argument to the OpenConnection method. When used with a stand-alone rdoConnection or rdoQuery objects, the Connect property is used by the EstablishConnection method.
Except when associated with the RemoteData control, once a connection is made, the Connect property is completed with the values optionally supplied by the user and the ODBC driver manager. The Connect property of the rdoQuery contains this amended connect string.
The RemoteData control's Connect property is not changed after the connection is established. However, the completed connect string can be extracted from the RemoteData control's Connection property. For example:
FullConnect = MSRDC1.Connection.Connect
The following table details valid ODBC connect string arguments and typical usage. Note that each parameter is delineated with a semi-colon (;).
ODBC Connect String Arguments
Parameter | Specifies | Example |
DSN | Registered ODBC data source by name. | DSN=MyDataSource; (If specified when establishing a DSN-less connection, DSN must be the last argument) |
UID | User name of a recognized user of the database | UID=Victoria; |
PWD | Password associated with user name | PWD=ChemMajor; |
DRIVER | Description of driver. (Note brackets for driver names that include spaces.) | DRIVER={SQL Server}; |
DATABASE | Default database to use once connected | DATABASE=Pubs; |
SERVER | Name of remote server | SERVER=SEQUEL; |
WSID | Workstation ID (your system's Net name) | WSID=MYP5 |
APP | Application name. At design time this is set to your project name. At runtime this is your .exe name. | APP=Accounting |
Note Some ODBC drivers require different parameters not shown in this list.
For example, to set the Connect property of a RemoteData control you could use code like the following:
Dim Cnct As String
Cnct = "DSN=WorkData;UID=Chrissy;" _
& "PWD=MIDFLD;DATABASE=WorkDB;"
RemoteData1.Connect = Cnct
RemoteData1.SQL = "Select Name, City " _
& " From Teams Where Type = 12"
RemoteData1.Refresh
You can use this same connect string to establish a new connection:
Dim Cn As rdoConnection
Set Cn = rdoEnvironments(0).OpenConnection("", _
rdDriverNoPrompt,True,Cnct$)
Note Valid parameters are determined by the ODBC driver. The parameters shown in the preceding example are supported by the Microsoft SQL Server ODBC driver. ODBC, LOGINTIMEOUT and DBQ are not valid parameters of the RemoteData control or the rdoConnection object's Connect property. These parameters are supported by the Microsoft Jet database engine, and not by the ODBC driver. To set login timeout delay, you must use the LoginTimeout property of the rdoEnvironment object.
Capturing Missing Arguments
If the connect string is null, the information provided by the DSN is incomplete, or invalid arguments are provided, the connection cannot be established. If your code sets the prompt argument of the OpenConnection method or the RemoteData control's Prompt property to prohibit user completion of missing ODBC connect arguments, a trappable error is triggered. Otherwise the ODBC driver manager displays a dialog box to gather missing information from the user. Depending on the setting of the Prompt argument of the OpenConnection or EstablishConnection methods, these dialogs capture the DSN from a list of registered ODBC data sources.Names presented to the user, and optionally, the user ID and password. If the connection fails to succeed using these user-provided values, the dialogs are presented again until the connection succeeds or the user cancels the operation. In some cases, the user can create their own DSN using these dialogs.
If a password is required, but not provided in the Connect property setting, a login dialog box is displayed the first time a table is accessed by the ODBC driver and each time the connection is closed and reopened.
Connecting with Domain-Managed Security
When connecting to ODBC data sources that support domain-managed security, set the UID and PWD parameters to "". In this case, the Windows NT user name and password are passed to the data source for validation. This strategy permits access to the data source by users with access to the NT domain through authenticated workstation logons.
You can set the Connect property for an rdoConnection object by providing a connect argument to the OpenConnection method. Once the connection is established, you can check the Connect property setting to determine the DSN, database, user name, password, or ODBC data source of the database.
Registering Data Source Names
Before you can establish a connection using a Data Source Name (DSN), you must either manually register the DSN using the Windows control panel application or use the rdoRegisterDataSource method. This process establishes the server name, driver name and other options used when referencing this data source.
Establishing DSN-Less Connections
Under the right circumstances you might not need to pre-register a DSN before connecting. If the following conditions are met, RDO can establish a DSN-less connection using the RemoteData control, or the OpenConnection or EstablishConnection methods with a fully-populated Connect property or connect string: