HOWTO: Pass Multiple DBPROPSETs to CDataSource::OpenID: Q191747
|
This article demonstrates how to use ATL OLE DB Consumer Classes for passing multiple DBPROPSETs to CDataSource::Open. It also shows how to use provider-specific properties of the SQLOLEDB provider because this represents a good example of when you would want to use multiple property sets.
// In the provider-specific property set DBPROPSET_SQLSERVERDBINIT,
// SQLOLEDB defines additional initialization properties such as
// SSPROP_INIT_APPNAME ( VT_BSTR ).
// You need the SQLOLEDB provider include file, sqloledb.h.
#include <atldbcli.h>
#define DBINITCONSTANTS
#include <sqloledb.h>
void SomeFunc()
{
...
CDataSource connection1 ;
CDBPropSet propset[2]={DBPROPSET_DBINIT, DBPROPSET_SQLSERVERDBINIT};
propset[0].AddProperty(DBPROP_INIT_DATASOURCE, L"mySQLServer");
propset[0].AddProperty(DBPROP_INIT_CATALOG, L"pubs");
propset[0].AddProperty(DBPROP_AUTH_USERID, L"sa");
propset[1].AddProperty(SSPROP_INIT_APPNAME,
L"SQLOLEDB ATL Consumer");
hr = connection1.Open("SQLOLEDB", propset, 2);
BSTR bstr;
connection1.GetInitializationString(&bstr);
...
}
To see the complete connection string including the extended properties,
drag the address of the BSTR and drop it in the debugger's memory window.Q190725 FILE: SqlOleDb.h Not Installed by VC++ 6.0
The following article in the Microsoft Knowledge Base describes the requirements to add OLE DB template support to Visual C++ projects:
Q190959 PRB: OLE DB Consumer Template Wizard Requires ATL Project
Additional query words:
Keywords : kbOLEDB kbSQLServ kbVC600
Version : WINNT:6.0
Platform : winnt
Issue type : kbhowto
Last Reviewed: August 3, 1999