Connecting to a Data Source Using the PromptFileName Method - OLE DB Provider for Teradata

OLE DB Provider for Teradata User Guide

Product
OLE DB Provider for Teradata
Release Number
15.00
Language
English (United States)
Last Update
2018-09-28
dita:id
B035-2498
Product Category
Teradata Tools and Utilities

Connecting to a Data Source Using the PromptFileName Method

To connect to a data source using the PromptFileName method

1 The consumer has previously saved the Data Link Properties dialog field information to a Universal Data Link file by using IDataInitialize::WriteStringToStorage.

The Universal Data Link (.udl) file contains the complete provider string that OLE DB Provider for Teradata uses to connect to the Data Source. Several .udl files can each contain different parameters for connecting to different Data Sources.

For a description of the Data Link Properties dialog box, see “Connecting Using PromptDataSource” on page 34.

2 The consumer calls the IDBPromptInitialize::PromptFileName method to obtain the path to the .udl file.

3 The IDBPromptInitialize::PromptFileName method displays the Organize Data Link Files dialog box.

4 The user clicks on the .udl file associated with the desired Data Source.

The file name highlights.

5 The user clicks Open.

6 The IDBPromptInitialize::PromptFileName method passes the .udl file name and path to the consumer. The consumer makes a method call to IDataInitialize::LoadStringFromStorage.

7 The IDataInitialize::LoadStringFromStorage method retrieves the connection string from the .udl file. The consumer makes a method call toIDataInitialize::GetDataSource.The IDataInitialize::GetDataSource method retrieves the Data Source object that is based on the connection string.

Example – Visual C++

This Visual C++ example uses the IDBPromptInitialize::PromptFileName method.

 
#include <oledb.h>
#include <oledberr.h>
#include <msdasc.h>
#include <oleauto.h>
 
void main()
{
HRESULT          hr;
CLSID            clsid;
IDBInitialize    *pIDBInitialize = NULL;
IDataInitialize  *pIDataInitialize = NULL;
DBPROPSET        rgPropertySet[1];
DBPROP           rgProperties[2];
WCHAR            *pwszUDLFile = NULL;
WCHAR            *pwszInitString = NULL;
 
//*************************************************
// Error handling is not included in this example. 
//*************************************************
 
hr = CoCreateInstance(CLSID_DataLinks, 
NULL, 
CLSCTX_INPROC_SERVER, 
IID_IDBPromptInitialize, 
(void **)&pIDBPromptInitialize);
 
HWND  hwnd = GetDesktopWindow();
 
 
// Getting the path to the UDL file

hr = pIDBPromptInitialize->PromptFileName(hwnd,

DBPROMPTOPTIONS_BROWSEONLY, 
L"I:\\", 
L"*.udl", 
&pwszUDLFile);
 
 
// Need to query interface for IDataInitialize
hr = pIDBPromptInitialize->QueryInterface(IID_IDataInitialize, (void **)&pIDataInitialize);
 
 
// Retrieving the connection string from the UDL file
hr = pIDataInitialize->LoadStringFromStorage(pwszUDLFile, &pwszInitString);
 
 
// Retrieving the un-initialized Data Source that is based on 
// the connection string
 
hr = pIDataInitialize->GetDataSource(NULL, 
CLSCTX_INPROC_SERVER, 
pwszInitString, 
IID_IDBInitialize, 
(IUnknown **)&pIDBInitialize);
 
 
// Initialize the Data Source object.
 
hr = pIDBInitialize->Initialize();
 
 
// This is just an example and we assume S_OK was returned
//-------------------------------------------------------------
//
// REST OF PROGRAM …
//
//-------------------------------------------------------------
 
// Releasing all objects at the end of the program.
 
pIDBPromptInitialize->Release();
pIDataInitialize->Release();
pIDBInitialize->Release();
}