Opens a Connection object on an ODBC data source (ODBCDirect workspaces only).
Syntax
CdbConnectionOpenConnection(LPCTSTR pstrName,
LONG lOption=-1L,
BOOL bReadOnly=FALSE,
LPCTSTR pstrConnect=NULL);
Parameters
Type | Example | Description |
LPCTSTR | pstrName | A pointer to a 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. |
LONG | IOption | 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. |
BOOL | bReadOnly | Optional. A Boolean. TRUEOpens a Connection object for read-only access. FALSE(Default) Opens a Connection object for read/write access. |
LPCTSTR | pstrConnect | 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 Connect is omitted (default), the UID and/or PWD will be taken from the UserName and Password properties of the Workspace. |
Remarks
The following are valid Options values.
Constant | Description |
dbDriverNoPrompt | The ODBC driver manager uses the connection string provided in Name and Connect. If sufficient information is not provided, a trappable error is returned. |
dbDriverPrompt | The driver manager displays the ODBC Data Sources dialog box. The connection string used to establish the connection is constructed from the DSN selected and completed by the user via the dialog boxes, or, if no DSN is chosen, the default DSN is used. |
dbDriverComplete | If the Connect argument includes the DSN keyword, the driver manager uses the string as provided in Connect. Otherwise it behaves as it does when dbDriverPrompt is specified. |
dbDriverCompleteRequired | Behaves like dbDriverComplete except the driver disables the prompts for any information not required to complete the connection. |
dbRunAsync | Execute the method asynchronously. This constant may be used with any of the other Options constants. |
The OpenConnection method is similar but not equivalent to OpenDatabase. The main difference is that OpenConnection is available only in an ODBCDirect workspace.
Usage
#include <afxole.h>
#include <dbdao.h>
CdbDBEngine dben(..., dbUseODBC);
CdbWorkspace wksp;
CdbConnection conn;
CdbRecordset rstX;
wksp = dben.Workspaces[0L];
conn = wksp.OpenConnection(_T("ODBC;..."),
(dbDriverNoPrompt|dbRunAsync),
FALSE, T("DATABASE=SomeDB..."));
rstX = conn.OpenRecordset(...);