INFO: Using ActiveX Data Objects (ADO) via OLE SDK in VC++

ID: Q176342


The information in this article applies to:


SUMMARY

The OLE DB 1.x SDK and Data Access 2.x SDK contain two files, Adoid.h and Adoint.h, which make using ActiveX Data Objects (ADO) easier with the OLE DB SDK. This article discusses how to utilize the header files effectively.


MORE INFORMATION

Using ADOID.H and ADOINT.H

For ADO 1.x, add the \Oledbsdk\Include and \Oledbsdk\Lib folders to your path. For ADO 1.0 or 1.1 add Adoid.lib to the link step. For ADO 1.5 and later you need to explicitly remove this .lib file, and add an include to <initguid.h>, once in your application, prior to including theADOID.H/ADOINT.H file(s).

You may see the following warning message upon compilation:



  adoid.lib(adoid.obj) : warning LNK4099: PDB "dao40.pdb" was not found
                         with "c:\oledbsdk\lib\adoid.lib" or at <path>;                  
                         linking object as if no debug info 

This message can be ignored.

Before Instantiating any ADO Objects

It is important to initialize OLE before creating any instances of ADO objects using the OLE SDK. You may use the following code snippet:


struct InitOle {
InitOle()  { ::CoInitialize(NULL); }
~InitOle() { ::CoUninitialize();   }
} _init_InitOle_; 


If you have any global BSTRs, this is also a good place to allocate and deallocate them.

Error Handling

With ADO, you may receive an error in the HRESULT returned from an ADO method. This may or may not result in errors being filled in the ADO Errors Collection. The Errors collection only receives errors raised by the underlying provider (or drivers underneath that provider.) ADO errors are not populated in the collection but can be retrieved from the IErrorInfo interface.

The Adovc sample demonstrates how to catch exceptions or errors with ADO.

For additional information, please see the following article in the Microsoft Knowledge Base:

Q174565 FILE: Adovc.exe Demonstrates How to Use ADO with Visual C++

Passing the License Key to ADO and ADO Redistribution

ADO 1.0 requires a license key when run on any system that has ADO installed in a mechanism other than a Microsoft product. If the license key is already installed in the registry, then you do not need to pass a license key. Otherwise, instead of CoCreateInstance(), you use CoGetClassObject() to get a IClassFactory2 interface and CreateInstanceLic(). ADO 1.5 removed the need for a license key.


REFERENCES

"Inside COM", Dale Rogerson, Microsoft Press, February 1997, ISBN 1-57231-349-8

For more information, please see the following articles in the Microsoft Knowledge Base:

Q168354 INFO: Underlying OLE and OLEDB Provider Errors Exposed via ADO

Q169496 INFO: Using ActiveX Data Objects (ADO) via #import in VC++

Q175993 INFO: Using ActiveX Data Objects (ADO) via MFC OLE in VC++

Q176342 INFO: Using ActiveX Data Objects (ADO) via OLE SDK in VC++

Additional query words: kbdse


Keywords          : kbADO kbVC 
Version           : WINDOWS:1.0,1.5,2.0
Platform          : WINDOWS 
Issue type        : kbinfo 

Last Reviewed: March 5, 1999