Compartir a través de


DBPROP_INIT_PROMPT

Property group: Initialization

Property set: DBPROPSET_DBINIT

Type: VT_I2

Typical R/W: R/W

Description: Prompt

Indicates whether to prompt the user during initialization. One of the following values:

  • DBPROMPT_PROMPT ? Always prompt the user for initialization information.

  • DBPROMPT_COMPLETE ? Prompt the user only if more information is needed.

  • DBPROMPT_COMPLETEREQUIRED ? Prompt the user only if more information is needed. Do not allow the user to enter optional information.

  • DBPROMPT_NOPROMPT ? Do not prompt the user.

Information obtained from the user during prompting is available following initialization by calling GetProperties for the appropriate initialization properties.

Providers that do not wish to build their own prompting user interface can use IDBPromptInitialize::PromptDataSource, passing in their own data source object as the value of the ppDataSource argument. Such providers are still required to support DBPROP_INIT_PROMPT but can leverage the user interface provided by OLE DB services.

Example

// dbprop_init_prompt.cpp
#undef _ATL_DLL

#define _WIN32_DCOM 
#define DBINITCONSTANTS

#include <windows.h>
#include <atldbcli.h>
#include <sqloledb.h>

#define CLSID_PROVIDER_TO_USE  CLSID_SQLOLEDB

#define CHECKED(_hr) \
   do { \
      if (FAILED(hr = _hr)){ \
         PrintHR(hr); \
         return -1; \
      } \
   } while(0)

#define PrintHR(hr) PrintHR_internal(hr, __FILE__, __LINE__)

void PrintHR_internal(HRESULT hr, char * szFile, ULONG uLine) {
   wprintf(L"Error HR = %d (%x) %hs(%d)\n", hr, hr, szFile, uLine);
}

int GetDbInitializeFromClsid( IDBInitialize** ppDbInitialize ) {
   HRESULT hr;
   CComPtr< IDBInitialize > pDbInitialize;
   CHECKED( ::CoCreateInstance( CLSID_PROVIDER_TO_USE, NULL, CLSCTX_INPROC_SERVER, IID_IDBInitialize, (void**)&pDbInitialize ) );

   // Initialize the property values needed to establish the connection.
   DBPROP InitProperty;
   ::VariantInit(&InitProperty.vValue);

   InitProperty.dwPropertyID  = DBPROP_INIT_PROMPT;
   InitProperty.vValue.vt     = VT_I2;
   InitProperty.vValue.iVal   = DBPROMPT_PROMPT;
   InitProperty.dwOptions     = DBPROPOPTIONS_REQUIRED;
   InitProperty.colid         = DB_NULLID;

   DBPROPSET InitPropSet;
   InitPropSet.guidPropertySet = DBPROPSET_DBINIT;
   InitPropSet.cProperties    = 1;
   InitPropSet.rgProperties   = &InitProperty;

   // Set initialization properties.
   CComPtr< IDBProperties > pDbProperties;
   CHECKED( pDbInitialize->QueryInterface(IID_IDBProperties, (void **)&pDbProperties) );
   CHECKED( pDbProperties->SetProperties(1, &InitPropSet) );

   *ppDbInitialize = pDbInitialize.Detach();

   return 0;
}

int main() {
   HRESULT hr;
   CHECKED(::CoInitializeEx(NULL, COINIT_MULTITHREADED));
   CComPtr<IDBInitialize> pDbInitialize;
   GetDbInitializeFromClsid(&pDbInitialize);
   CHECKED(pDbInitialize->Initialize());
}

See Also

Reference

Properties (Alphabetical)