description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CDataSource Class |
CDataSource Class |
11/04/2016 |
|
|
99bf862c-9d5c-4117-9501-aa0e2672085c |
Corresponds to an OLE DB data source object, which represents a connection through a provider to a data source.
class CDataSource
Header: atldbcli.h
Name | Description |
---|---|
Close | Closes the connection. |
GetInitializationString | Retrieves the initialization string of the data source that is currently open. |
GetProperties | Gets the values of properties currently set for the connected data source. |
GetProperty | Gets the value of a single property currently set for the connected data source. |
Open | Creates a connection to a provider (data source) using either a CLSID , ProgID , or a CEnumerator moniker provided by the caller. |
OpenFromFileName | Opens a data source from a file specified by the user-supplied file name. |
OpenFromInitializationString | Opens the data source specified by an initialization string. |
OpenWithPromptFileName | Allows the user to select a previously created data link file to open the corresponding data source. |
OpenWithServiceComponents | Opens a data source object using the Data Link dialog box. |
One or more database sessions can be created for a single connection. These sessions are represented by CSession
. You must call CDataSource::Open to open the connection before creating a session with CSession::Open
.
For an example of how to use CDataSource
, see the CatDB sample.
Closes the connection by releasing the m_spInit
pointer.
void Close() throw();
Retrieves the initialization string of a data source that is currently open.
HRESULT GetInitializationString(BSTR* pInitializationString,
bool bIncludePassword = false) throw();
pInitializationString
[out] A pointer to the initialization string.
bIncludePassword
[in] true
if string includes a password; otherwise false
.
A standard HRESULT.
The resulting initialization string can be used to later reopen this data source connection.
Returns the property information requested for the connected data source object.
HRESULT GetProperties(ULONG ulPropIDSets,
constDBPROPIDSET* pPropIDSet,
ULONG* pulPropertySets,
DBPROPSET** ppPropsets) const throw();
See IDBProperties::GetProperties in the OLE DB Programmer's Reference in the Windows SDK.
A standard HRESULT.
To get a single property, use GetProperty.
Returns the value of a specified property for the connected data source object.
HRESULT GetProperty(const GUID& guid,
DBPROPID propid,
VARIANT* pVariant) const throw();
guid
[in] A GUID identifying the property set for which to return the property.
propid
[in] Property ID for the property to return.
pVariant
[out] A pointer to the variant where GetProperty
returns the value of the property.
A standard HRESULT.
To get multiple properties, use GetProperties.
Opens a connection to a data source using a CLSID
, ProgID
, or CEnumerator
moniker or prompts the user with a locator dialog box.
HRESULT Open(const CLSID& clsid,
DBPROPSET* pPropSet = NULL,
ULONG nPropertySets = 1) throw();
HRESULT Open(const CLSID& clsid,
LPCTSTR pName,
LPCTSTR pUserName = NULL,
LPCTSTR pPassword = NULL,
long nInitMode = 0) throw();HRESULT Open(LPCTSTR szProgID,
DBPROPSET* pPropSet = NULL,
ULONG nPropertySets = 1) throw();HRESULT Open(LPCTSTR szProgID,
LPCTSTR pName, LPCTSTR pUserName = NULL,
LPCTSTR pPassword = NULL,
long nInitMode = 0) throw();
HRESULT Open(const CEnumerator& enumerator,
DBPROPSET* pPropSet = NULL,
ULONG nPropertySets = 1) throw();
HRESULT Open(const CEnumerator& enumerator,
LPCTSTR pName,
LPCTSTR pUserName = NULL,
LPCTSTR pPassword = NULL,
long nInitMode = 0) throw();
HRESULT Open(HWND hWnd = GetActiveWindow(),
DBPROMPTOPTIONS dwPromptOptions = DBPROMPTOPTIONS_WIZARDSHEET) throw();
HRESULT Open(LPCWSTR szProgID,
DBPROPSET* pPropSet = NULL,
ULONG nPropertySets = 1) throw();
HRESULT Open(LPCSTR szProgID,
LPCTSTR pName,LPCTSTR pUserName = NULL,
LPCTSTR pPassword = NULL,
long nInitMode = 0) throw();
clsid
[in] The CLSID
of the data provider.
pPropSet
[in] A pointer to an array of DBPROPSET structures containing properties and values to be set. See Property Sets and Property Groups in the OLE DB Programmer's Reference in the Windows SDK.
nPropertySets
[in] The number of DBPROPSET structures passed in the pPropSet argument.
pName
[in] The name of the database to which to connect.
pUserName
[in] The name of the user.
pPassword
[in] The user's password.
nInitMode
[in] Database initialization mode. See Initialization Propertiesin the OLE DB Programmer's Reference in the Windows SDK for a list of valid initialization modes. If nInitMode is zero, no initialization mode is included in the property set used to open the connection.
szProgID
[in] A program identifier.
enumerator
[in] A CEnumerator object used to obtain a moniker for opening the connection when the caller does not specify a CLSID
.
hWnd
[in] Handle to the window that is to be the parent of the dialog box. Using the function overload that uses the hWnd parameter will automatically invoke Service Components; see Remarks for details.
dwPromptOptions
[in] Determines the style of locator dialog box to display. See Msdasc.h for possible values.
A standard HRESULT.
The method overload that uses the hWnd parameter opens a data source object with the service components in oledb32.dll; this DLL contains the implementation of Service Components features such as Resource Pooling, Automatic Transaction Enlistment, and so on. For more information, see the OLE DB reference in the OLE DB Programmer's Guide.
The method overloads that do not use the hWnd parameter open a data source object without using the service components in oledb32.dll. A CDataSource object opened with these function overloads will be unable to utilize any of the functionality of Service Components.
The following code shows how to open a Jet 4.0 data source with OLE DB Templates. You treat the Jet data source as an OLE DB data source. However, your call to Open
needs two property sets: one for DBPROPSET_DBINIT and the other for DBPROPSET_JETOLEDB_DBINIT, so that you can set DBPROP_JETOLEDB_DATABASEPASSWORD.
[!code-cppNVC_OLEDB_Consumer#7]
Opens a data source from a file specified by the user-supplied file name.
HRESULT OpenFromFileName(LPCOLESTR szFileName) throw();
szFileName
[in] The name of a file, usually a data source connection (.UDL) file.
For more information about data link files (.udl files), see Data Link API Overview in the Windows SDK.
A standard HRESULT.
This method opens a data source object using the service components in oledb32.dll; this DLL contains the implementation of Service Components features such as Resource Pooling, Automatic Transaction Enlistment, and so on. For more information, see the OLE DB reference in the OLE DB Programmer's Guide.
Opens a data source specified by the user-supplied initialization string.
HRESULT OpenFromInitializationString(LPCOLESTR szInitializationString,
bool fPromptForInfo= false) throw();
szInitializationString
[in] The initialization string.
fPromptForInfo
[in] If this argument is set to true
, then OpenFromInitializationString
will set the DBPROP_INIT_PROMPT property to DBPROMPT_COMPLETEREQUIRED, which specifies that the user be prompted only if more information is needed. This is useful for situations in which the initialization string specifies a database that requires a password, but the string does not contain the password. The user will be prompted for a password (or any other missing information) when trying to connect to the database.
The default value is false
, which specifies that the user never be prompted (sets DBPROP_INIT_PROMPT to DBPROMPT_NOPROMPT).
A standard HRESULT.
This method opens a data source object using the service components in oledb32.dll; this DLL contains the implementation of Service Components features such as Resource Pooling, Automatic Transaction Enlistment, and so on.
This method prompts the user with a dialog box, then opens a data source using the file specified by the user.
HRESULT OpenWithPromptFileName(HWND hWnd = GetActiveWindow( ),
DBPROMPTOPTIONS dwPromptOptions = DBPROMPTOPTIONS_NONE,
LPCOLESTR szInitialDirectory = NULL) throw();
hWnd
[in] Handle to the window that is to be the parent of the dialog box.
dwPromptOptions
[in] Determines the style of locator dialog box to display. See Msdasc.h for possible values.
szInitialDirectory
[in] The initial directory to display in the locator dialog box.
A standard HRESULT.
This method opens a data source object using the service components in oledb32.dll; this DLL contains the implementation of Service Components features such as Resource Pooling, Automatic Transaction Enlistment, and so on. For more information, see the OLE DB reference in the OLE DB Programmer's Guide.
Opens a data source object using the service components in oledb32.dll.
HRESULT OpenWithServiceComponents (const CLSID clsid,
DBPROPSET* pPropset = NULL,
ULONG ulPropSets = 1);
HRESULT OpenWithServiceComponents (LPCSTR szProgID,
DBPROPSET* pPropset = NULL,
ULONG ulPropSets = 1);
clsid
[in] The CLSID
of a data provider.
szProgID
[in] Program ID of a data provider.
pPropset
[in] A pointer to an array of DBPROPSET structures containing properties and values to be set. See Property Sets and Property Groups in the OLE DB Programmer's Reference in the Windows SDK. If the data source object is initialized, the properties must belong to the Data Source property group. If the same property is specified more than once in pPropset, then which value is used is provider-specific. If ulPropSets is zero, this parameter is ignored.
ulPropSets
[in] The number of DBPROPSET structures passed in the pPropSet argument. If this is zero, the provider ignores pPropset.
A standard HRESULT.
This method opens a data source object using the service components in oledb32.dll; this DLL contains the implementation of Service Components features such as Resource Pooling, Automatic Transaction Enlistment, and so on. For more information, see the OLE DB reference in the OLE DB Programmer's Guide.
OLE DB Consumer Templates
OLE DB Consumer Templates Reference