OLE DB Programmer's Reference |
Given a connection string, instantiates and returns an uninitialized data source object.
HRESULT GetDataSource( IUnknown * pUnkOuter, DWORD dwClsCtx, LPCOLESTR pwszInitializationString, REFID riid, IUnknown ** ppDataSource);
Parameters
64-bit: If pwszInitializationString is NULL, an instance of the SQLOLEDB provider is returned with default properties set.
If *ppDataSource is null on entry, IDataInitialize::GetDataSource generates a new data source object based on the information in pwszInitializationString and returns a pointer to that data source object in *ppDataSource.
If *ppDataSource is null and no provider is specified in pwszInitializationString, the data source object will be defaulted to the OLE DB Provider for ODBC.
If *ppDataSource is non-null and no provider is specified in pwszInitializationString, the data source specified by *ppDataSource will be used.
If *ppDataSource is non-null on entry and a provider is specified in pwszInitializationString, IDataInitialize::GetDataSource checks to see whether the specified provider matches the data source object passed in *ppDataSource. If so, GetDataSource sets the specified properties on the existing data source object. If not, GetDataSource returns an error and leaves *ppDataSource untouched.
Return Code
riid was IID_NULL.
*ppDataSource was not null and did not indicate an OLE DB data source object.
pwszInitializationString specified a provider, pUnkOuter was not a null pointer, and the provider does not support aggregation.
dwClsCtx required out-of-process operation, which is not supported.
The provider does not support in-process operation and cannot be aggregated.
ppDataSource was a null pointer.
*ppDataSource and pUnkOuter were both non-null. *ppDataSource cannot be aggregated in *pUnkOuter because it has already been created.
dwClsCtx indicated a server type not supported by the provider specified in pwszInitializationString.
Properties were specified in pwszInitializationString but *ppDataSource indicated a data source that was already initialized.
A property specified in pwszInitializationString was a read-only property, and the property was not set to its default value.
It was not possible to set a property specified in pwszInitializationString.
One or more properties specified in pwszInitializationString conflicted with an existing property or with one another.
Comments
None.
Code Example
The following code fragment shows how a consumer might use IDataInitialize to connect to a data source object:
HRESULT hr = S_OK; IDBInitialize * pIDBInitialize = NULL; IDataInitialize * pIDataInitialize = NULL; hr = CoCreateInstance( CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER, IID_IDataInitialize, reinterpret_cast<LPVOID *>(&pIDataInitialize)); if (!SUCCEEDED(hr)) return hr; hr = pIDataInitialize->GetDataSource( NULL, CLSCTX_INPROC_SERVER, L"Provider=MSDAORA;User ID=Oracle;Data Source=\\ORACLE", IID_IDBInitialize, reinterpret_cast<IUnknown **>(&pIDBInitialize));
1998-2001 Microsoft Corporation. All rights reserved.