DOCUMENT:Q187529 15-JUN-1998 [vbwin] TITLE :HOWTO: Using ADO to Access Objects Through ADSI LDAP Provider PRODUCT :Microsoft Visual Basic for Windows PROD/VER:WINDOWS:5.0 OPER/SYS:WINDOWS KEYWORDS: ====================================================================== --------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 16-bit and 32-bit, for Windows, version 5.0, on the following platforms: Alpha, NT, Win95, x86 --------------------------------------------------------------------- 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: server is the name (or IP address) of the server hosting the directory. adsidn is the distinguished name (DN) of the starting point for your query expressed ADsPath format with "/" separators and the root of the namespace to the left. You can also use an X.500 style attributed name format with the relative distinguished names separated by commas and the root of the name space to the right. filter is the LDAP filter string (see rfc2254). attributescsv is a comma separated list of names of the attributes to be returned for each row in the recordset. scope is either: base, onelevel, or subtree. 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:; (objectClass=*); ADsPath,objectClass,cn;subtree" or (in attributed name format): , (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( _ "; _ (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 REFERENCES ========== Additional query words: kbVBp500 kbSDKPlat kbADO kbADSI kbDSupport kbdse ====================================================================== Version : WINDOWS:5.0 Platform : WINDOWS Issue type : kbhowto ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 1998.