Link to home
Start Free TrialLog in
Avatar of Pber
PberFlag for Canada

asked on

AD LDAP problem with range limits.

I'm trying to retrieve more than 1000 user objects in Active Directory.  Since AD limits searches at 1000, from what I've seen you have to use the 'Range' command in a LDAP query to get around this.

In this example I'm only trying to retrieve a small amount of objects just for testing purposes.  
Ultimately I would change the code and set the range=0-999 and loop through the ranges until all objects were obtained.

It works when I don't specify a range, but when I define a range, it apparently still finds 1000 records, but no values in the returned data.

Any ideas on what is going wrong?


Private Sub cmdAD_Click()
'On Error Resume Next
   Dim conn As ADODB.Connection
   Dim rs As ADODB.Recordset
   Dim x As Integer
   
   List1.Clear
   
   Set conn = New ADODB.Connection
   conn.Provider = "ADSDSOObject"
   conn.Open "ADs Provider"
   
   Set rs = conn.Execute("<LDAP://MyDC>;(ObjectCategory=user);name;subtree")                  'This works - 1000 records, 1000 list items
   'Set rs = conn.Execute("<LDAP://MyDC>;(ObjectCategory=user);name;range=0-50;subtree")      'This doesn't - 1000 records, 0 list items
   
   Debug.Print "Records: " & rs.RecordCount
   
   While Not rs.EOF
      If rs.Fields(0).Value <> "" Then
         List1.AddItem rs.Fields("name").Value
      End If
      rs.MoveNext
   Wend
   
   Debug.Print "List items:" & List1.ListCount
   
   conn.Close
   
   Set rs = Nothing
   Set conn = Nothing
End Sub

ASKER CERTIFIED SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pber

ASKER

I've been working with the following microsoft example:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/adsi/example_code_for_using_ranging_to_retrieve_members_of_a_group.asp

This example does not seem to follow the above range rules.

What does this mean:
"the search query function would request the member;range=1000-* values, which would return the member;range=1000-* attribute with no values and a member;range=1000-1999 attribute with the next 1000 values."

my problem seems to be I get the first batch of attributes with not values, but how does one obtain the second batch of attributes with the actual values?
Avatar of Pber

ASKER

I forgot to mention, I running a native Windows 2003 domain and using a Windows 2000 SP4 workstation to perform the query.
I am out of ideas, hopefully someone can step in.