LDAP Dialect
The LDAP dialect is a format for query statements that use the LDAP search filter syntax. Use an LDAP query statement with the following ADSI search interfaces:
- The ActiveX Data Object (ADO) interfaces, which are Automation interfaces that use OLE DB.
- OLE DB, which is a set of C/C++ interfaces for querying databases.
- IDirectorySearch, which is the C/C++ interface for Active Directory.
An LDAP dialect string consists of four parts separated by semicolons (;).
-
Base distinguished name. For example:
<LDAP://DC=Fabrikam,DC=COM>
- LDAP search filters. For more information about search filters, see Search Filter Syntax.
- The LDAP display name of the attributes to retrieve. Multiple attributes are separated by a comma.
- Specifies the scope of the search. Valid values are "base", "onelevel", and "subtree". The scope specified in an LDAP query string overrides any search scope specified with the "SearchScope" property of the ADO Command object.
The following is a code example of the LDAP dialect in ADSI that searches all the objects in the subtree.
"<LDAP://DC=Fabrikam,DC=com>;(objectClass=*);AdsPath, cn;subTree"
Not all search options (search page size, for example) can be expressed in the LDAP dialect, so you must set the options before the actual query execution starts.
Example Code for Performing an LDAP Query
The following code example shows how to use an LDAP query
Dim con As New Connection, rs As New Recordset Dim adVariant Dim i 'Used for counter Dim j 'Used for counter Dim Com As New Command Dim strDomain As String Dim strPassword As String ' Open a Connection object. con.Provider = "ADsDSOObject" con.Properties("ADSI Flag") = 1 con.Properties("User ID") = strDomain + "\" + strUserID con.Properties("Password") = strPassword con.Open "Active Directory Provider" ' Create a command object on this connection. Set Com.ActiveConnection = con ' Set the query string. Com.CommandText = "<LDAP://MyServer/DC=MyDomain,DC=Fabrikam,DC=com>; (objectClass=*);ADsPath, objectclass;base" ' Set search preferences. Com.Properties("Page Size") = 1000 Com.Properties("Timeout") = 30 'seconds ' Execute the query. Set rs = Com.Execute ' Navigate the record set. rs.MoveFirst While Not rs.EOF For i = 0 To rs.Fields.Count - 1 If rs.Fields(i).Type = adVariant And Not (IsNull(rs.Fields(i).Value)) Then Debug.Print rs.Fields(i).Name, " = " For j = LBound(rs.Fields(i).Value) To UBound(rs.Fields(i).Value) Debug.Print rs.Fields(i).Value(j), " # " Next j Else Debug.Print rs.Fields(i).Name, " = ", rs.Fields(i).Value End If Next i rs.MoveNext Wend rs.MoveLast Debug.Print "No. of rows = ", rs.RecordCount
For details about the query syntax, see Search Filter Syntax.
Related topics
- Search Filter Syntax
- SQL dialect
- Searching with the IDirectorySearch Interface
- Searching with ActiveX Data Objects
- Searching with OLE DB