Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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.
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.
Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register today