Microsoft KB Archive/191747

= How To Pass Multiple DBPROPSETs to CDataSource::Open =

Article ID: 191747

Article Last Modified on 3/2/2005

-

APPLIES TO

 Microsoft OLE DB 2.0, when used with:  Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Professional Edition

 Microsoft Visual C++ 6.0 Standard Edition 

-

<div class="notice_section">

This article was previously published under Q191747

<div class="summary_section">

SUMMARY
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.

<div class="moreinformation_section">

Sample Code
// 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.

NOTE: there is an error in the online Help for CDataSource::Open. It does not show the third parameter, the number of DBPROPSETs.

NOTE: SQLOLEDB.h is not installed by Visual C++, version 6.0. The following article in the Microsoft Knowledge Base shows how to get the header file:

190725 FILE: SqlOleDb.h Not Installed by VC++ 6.0

<div class="references_section">