Initializing the Data Source
After the consumer sets all the desired properties, the consumer calls IDBInitialize::Initialize to initialize the Teradata Data Source.
Example – Visual C++
This Visual C++ example sets the properties needed to successfully initialize the Teradata Data Source, and sets the provider string property DBPROP_INIT_PROVIDERSTRING.
#include <oledb.h>
#include <oledberr.h>
#include <msdasc.h>
#include <oleauto.h>
void main()
{
HRESULT hr;
CLSID clsid;
IDBInitialize *pIDBInitialize = NULL;
IDBProperties *pIDBProperties = NULL;
DBPROPSET rgPropertySet[1];
DBPROP rgProperties[4];
//*************************************************************
// Error handling is not included in this example.
//*************************************************************
// Retrieving the class id
hr = CLSIDFromProgID(L"TDOLEDB", &clsid);
// Creating an instance of TDOLEDB
hr = CoCreateInstance(clsid,
NULL,
CLSCTX_INPROC_SERVER,
NULL,
IID_IDBInitialize,
(IUnknown **)&pIDBInitialize);
hr = pIDBInitialize->QueryInterface(IID_IDBProperties,
void **)&pIDBProperties);
// Setting up the properties needed to initialize the Data Source
// Specifying the password
rgProperties[0].dwOptions = DBPROPOPTIONS_REQUIRED;
rgProperties[0].dwPropertyID = DBPROP_AUTH_PASSWORD;
rgProperties[0].dwStatus = 0;
rgProperties[0].colid = DB_NULLID;
V_VT(&(rgProperties[0].vValue)) = VT_BSTR;
V_BSTR(&(rgProperties[0].vValue)) =
SysAllocString(L"YourPassword");
// Specifying the user name
rgProperties[1].dwOptions = DBPROPOPTIONS_REQUIRED;
rgProperties[1].dwPropertyID = DBPROP_AUTH_USERID;
rgProperties[1].dwStatus = 0;
rgProperties[1].colid = DB_NULLID;
V_VT(&(rgProperties[1].vValue)) = VT_BSTR;
V_BSTR(&(rgProperties[1].vValue)) = SysAllocString(L"YourUserId");
// Specifying the Data Source. The Data Source refers to the
TDPID.
rgProperties[2].dwOptions = DBPROPOPTIONS_REQUIRED;
rgProperties[2].dwPropertyID = DBPROP_INIT_DATASOURCE;
rgProperties[2].dwStatus = 0;
rgProperties[2].colid = DB_NULLID;
V_VT(&(rgProperties[2].vValue)) = VT_BSTR;
V_BSTR(&(rgProperties[2].vValue)) =
SysAllocString(L"TERADATA1");
// Specifying provider string
rgProperties[3].dwOptions = DBPROPOPTIONS_REQUIRED;
rgProperties[3].dwPropertyID = DBPROP_INIT_PROVIDERSTRING;
rgProperties[3].dwStatus = 0;
rgProperties[3].colid = DB_NULLID;
V_VT(&(rgProperties[3].vValue)) = VT_BSTR;
V_BSTR(&(rgProperties[3].vValue)) =
SysAllocString(L"SessionMode=ANSI;Enable Parser=Yes;UseXViews=YES");
rgPropertySet->cProperties = 4;
rgPropertySet->guidPropertySet = DBPROPSET_DBINIT;
rgPropertySet->rgProperties = rgProperties;
// Setting the properties
hr = pIDBProperties->SetProperties(1, rgPropertySet);
// Initializing the Data Source
hr = pIDBInitialize->Initialize();
// This is just an example and we assume S_OK was returned.
//-------------------------------------------------------------
//
// REST OF PROGRAM …
//
//-------------------------------------------------------------
// Releasing all objects at end of program
gIDBProperties->Release();
pIDBInitialize->Release();
}