如何限制LDAP查询中的结果数

时间:2014-07-02 06:59:27

标签: ldap limit adodb word-2010

我正在编写需要与Active Directory交互的Office 2010 Word模板,以检索一些用户信息。填写模板的用户可以为用于检索AD信息的搜索提供一些输入。 我正在使用ADODB Recordset和Command来设置我的查询:

Public Function GetActiveDirectoryInfo(searchString As String) As Object
 Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
 Dim strQuery, adoRecordset

 'remove user input asteriks
 searchString = Replace(searchString, "*", "")

 ' Setup ADO objects.
 Set adoCommand = CreateObject("ADODB.Command")
 Set adoConnection = CreateObject("ADODB.Connection")
 adoConnection.Provider = "ADsDSOObject"
 adoConnection.Open "Active Directory Provider"
 Set adoCommand.ActiveConnection = adoConnection

 strBase = "<LDAP://" & GLOBAL_LDAP_USER_OU & ">"

 ' Filter on user objects.
 strFilter = "(&(objectCategory=person)(objectClass=user)(|(sn=" & searchString & "*)(cn=" & searchString & "*)))"

 ' Comma delimited list of attribute values to retrieve.
 strAttributes = ACTIVE_DIRECTORY_FIELDS

 ' Construct the LDAP syntax query.
 strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";OneLevel"
 adoCommand.CommandText = strQuery
 adoCommand.Properties("Page Size") = 10
 adoCommand.Properties("Timeout") = 30
 adoCommand.Properties("Cache Results") = False
 'adoCommand.Properties("Maximum Rows") = 10  'error: read only

 On Error GoTo err_NoConnection

 ' Run the query.
 Set adoRecordset = adoCommand.Execute

 Set foundItems = adoRecordset
 Debug.Print "Found : " & foundItems.RecordCount & " records"

  Exit Function

err_NoConnection:
  'in case of error: return <nothing>
  Debug.Print Err.description
  Set GetActiveDirectoryInfo = Nothing
End Function

此功能是MS Word中用户类的一部分。

我的问题:如何阻止用户检索数千条记录?我一直在阅读有关分页的内容,但这看起来更像是一个网络负载,而不是实际限制最终会回复给我的搜索结果。

我尝试了几件事,但没有结果。例如,设置MaxRecords或Maximum Rows属性。两者都给出错误(第一个是非现有属性,第二个是只读错误)。

任何想法的人。

MS Office 2010荷兰人 ADO Objects 6.0

感谢名单!

1 个答案:

答案 0 :(得分:0)

ADO MaxRecord未实现限制搜索结果数量的ADsDSObject {{1}}。链接https://support.microsoft.com/kb/269361详细说明了解决问题的解决方法。