Article ID: 191746
Article Last Modified on 3/2/2005
HRESULT hr ;
//Initialize COM.
hr = CoInitialize(NULL);
CDataSource connection1 ;
CDataSource connection2 ;
CDataSource connection3 ;
// ===================================================
// Method #1: Setting OLE DB Initialization Properties
// ===================================================
CDBPropSet propset(DBPROPSET_DBINIT);
propset.AddProperty(DBPROP_INIT_DATASOURCE, L"mySQLServer");
propset.AddProperty(DBPROP_INIT_CATALOG, L"pubs");
propset.AddProperty(DBPROP_AUTH_USERID, L"<username>");
propset.AddProperty(DBPROP_AUTH_PASSWORD, L"<strong name>");
hr = connection1.Open("SQLOLEDB", &propset);
connection1.Close();
// ===================================================
// Method #2: Using MS Data Link dialog
// ===================================================
hr = connection2.Open(GetDesktopWindow());
BSTR bstr;
connection2.GetInitializationString(&bstr);
// bstr contains the initialization string.
connection2.Close();
// ===================================================
// Method #3: Supplying a provider string
// ===================================================
// This may take a relatively longer amount of time.
hr = connection3.OpenFromInitializationString
(L"Provider=SQLOLEDB;User ID=<username>;Password=<strong name>;Data Source=mySQLServer;
Initial Catalog=pubs;");
connection3.Close();
190959 PRB: OLE DB Consumer Template Wizard Requires ATL Project
Keywords: kbhowto kbconsumer kbdatabase kbdtl KB191746