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:
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
Send comments about this topic to Microsoft
Build date: 9/6/2011