大网数据广告活动
域与目录服务

LDAP Dialect

· 52CE 我爱测

The LDAP dialect is a format for query statements that use the LDAP search filter syntax.

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

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

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。