Navigation:  DAO Object Classes > DaoWorkspace Class >

DaoWorkspace:OpenConnection() Method

Previous pageReturn to chapter overviewNext page

Purpose

Opens a specified database

 

 

Parameters

cNameA string that contains the name of a registered ODBC data source (DSN). If it doesn't refer to a valid ODBC data source name, an error occurs
liOptions(Optional) A Long value that specifies how the ODBC driver manager should prompt the user for connection information such as DSN, user name, and password. Possible values are described in Remarks
lReadOnly(Optional)        TRUE Opens a Connection object for read-only access.

 FALSE (Default) Opens a Connection object for read/write access

cConnect(Optional) A pointer to a string that contains the ODBC connect string. See the connect property for the specific elements and syntax of this string. A prepended "ODBC;" is required. If cConnect is omitted (default), the UID and/or PWD will be taken from the UserName and Password properties of the Workspace

 

Returns

A Connection Object

 

Settings

The lOptions argument determines if and when to prompt the user to establish the connection, and whether or not to open the connection asynchronously. You can use one of the following constants.

 

ConstantDescription

 

dbDriverNoPromptThe ODBC Driver Manager uses the connection string provided in pstrName and pstrConnect. If you don't provide sufficient information, a        run-time error occurs.
dbDriverPromptThe ODBC Driver Manager displays the ODBC Data Sources dialog box, which displays any relevant information supplied in pstrNname or pstrConnect. The connection string is made up of the DSN that the user selects via the dialog boxes, or, if the user doesn't specify a DSN, the default DSN is used.
dbDriverCompleteDefault. If the pstrConnect argument includes all the necessary information to complete a connection, the ODBC Driver Manager uses the string in pstrConnect. Otherwise it behaves as it does when you specify dbDriverPrompt.
dbDriverCompleteRequiredThis option behaves like dbDriverComplete except the ODBC driver disables the prompts for any information not required to complete the connection.
dbRunAsyncExecute the method asynchronously. This constant may be used with any of the other lOptions constants.

 

Remarks

 

Use the OpenConnection method to establish a connection to an ODBC data source from an ODBCDirect workspace. The OpenConnection method is similar but not equivalent to OpenDatabase. The main difference is that OpenConnection is available only in an ODBCDirect workspace.

 

If you specify a registered ODBC data source name (DSN) in the connect argument, then the cName argument can be any valid string, and will also provide the Name property for the Connection object. If a valid DSN is not included in the cConnect argument, then cName must refer to a valid ODBC DSN, which will also be the Name property. If neither name nor cConnect contains a valid DSN, the ODBC driver manager can be set (via the lOptions argument) to prompt the user for the required

connection information. The DSN supplied through the prompt then provides the Name property.

 

OpenConnection returns a Connection object which contains information about the connection. The Connection object is similar to a Database object. The principal difference is that a Database object usually represents a database, although it can be used to represent a connection to an ODBC data source from a Microsoft Jet workspace

 

Class

DaoWorkspace        

 

See Also

DaoConnection

DaoDriverPromptEnum()