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



The information in this article applies to:

  • ActiveX Data Objects (ADO) 1.0
  • ActiveX Data Objects (ADO) 1.5
  • ActiveX Data Objects (ADO) 2.0
  • ActiveX Data Objects (ADO) 2.1
  • ActiveX Data Objects (ADO) 2.1 SP2

This article was previously published under Q176342

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:

220152 Sample: ADOVC1 Simple ADO/VC++ Application


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

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

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

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

168354 INFO: Underlying OLE and OLEDB Provider Errors Are Exposed Through ADO

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


Modification Type:MinorLast Reviewed:3/2/2005
Keywords:kbDatabase kbinfo KB176342