HOWTO: Using ADO to Access Objects Through ADSI LDAP Provider

ID: Q187529


The information in this article applies to:


SUMMARY

The Active Directory Service Interfaces (ADSI) version 2.0 Lightweight Directory Access Protocol (LDAP) provider implements OLE DB interfaces that allow you to use ActiveX Data Objects (ADO) to access objects in LDAP compliant directories. You must create an ADO connection object and set its Provider property to "ADsDSOObject". You can specify any string, including "", as the connection string (first argument) of the ADO connection object's open method.

The connection object Execute method's CommandText (first object) is an LDAP query composed of four elements separated by semicolons, in the following format:

<LDAP://server/adsidn>;ldapfilter;attributescsv;scope

where:
NOTE: rfc2253 specifies the LDAP syntaxes on which the ADSI LDAP syntax is based.

To return the ADsPath, class, and cn attributes of all the objects in all the recipient containers in an Exchange server, you can use the following CommandText (in URL format):

   LDAP:<//server/o=organization/ou=site/cn=recipients>;
      (objectClass=*);
   ADsPath,objectClass,cn;subtree" 
or (in attributed name format):

  <LDAP://server/cn=recipients,ou=site,o=organization>, _
      (objectClass=*);ADsPath,objectClass;subtree 


MORE INFORMATION

The following Visual Basic 5.0 sample code illustrates this query:

Sample Code


   Dim conn As Connection
   Dim rs As Recordset

   Set conn = CreateObject("ADODB.Connection")
   conn.Provider = "ADSDSOObject"
   conn.Open "ADs Provider"

   Set rs conn.Execute( _
         "<LDAP://server/o=organization/ou=site/cn=recipients>; _
         (objectClass=*);ADsPath,objectClass,cn;subtree")

   While Not rs.EOF
      Debug.Print rs.Fields(0).Value, rs.Fields(1).Value, _
            rs.Fields(2).Value
      rs.MoveNext
   Wend

   conn.Close
 

Additional query words: kbVBp500 kbSDKPlat kbADO kbADSI kbDSupport kbdse


Keywords          : 
Version           : WINDOWS:5.0
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: May 11, 1999