CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2002
    Posts
    278

    ADO, LDAP default 1000 records??

    Does anyone know how to get around the default 1000 records (limitation) that are returned when doing LDAP queries? The code below only returns 1000 records. Records consisting of network login IDs and other information. There are well over 1000 login ids but the server only sends the first 1000. There is some sort of MaxPageSize attribute that is set to 1000 but I have no idea how to change it or get the full list of records from our LDAP server. If possible I need to know how go get around this from within VB. . . Anyone have any ideas?

    This sample code requires a reference to
    <Active DS Type Library>
    and
    <Microsoft ActiveX Data Objects 2.x Library>

    Code:
    Private Sub Command1_Click()
    Dim cnn As ADODB.Connection
    Dim rsLogins As ADODB.Recordset
    Dim oRoot As IADs
    Dim oDomain As IADs
    Dim sBase As String
    Dim sFilter As String
    Dim sDomain As String
    Dim sAttribs As String
    Dim sDepth As String
    Dim sQuery As String
    
        On Error GoTo GetLoginIDsErrHandler
        Set cnn = New ADODB.Connection
        
        Set oRoot = GetObject("LDAP://rootDSE")
        sDomain = oRoot.Get("defaultNamingContext")
        Set oDomain = GetObject("LDAP://" & sDomain)
        sBase = "<" & oDomain.ADsPath & ">"
        sFilter = "(&(objectCategory=person)(objectClass=user))"
        sAttribs = "distinguishedName"
        sDepth = "subTree"
        
        sQuery = sBase & ";" & sFilter & ";" & sAttribs & ";" & sDepth
        cnn.Open "Data Source=Active Directory Provider;Provider=ADsDSOObject"
       
        Set rsLogins = cnn.Execute(sQuery)
        rsLogins.MoveLast
        MsgBox rsLogins.RecordCount
    
    GetLoginIDsExitPoint:
        On Error Resume Next
        
        cnn.Close
        rsLogins.Close
        Set rsLogins = Nothing
        Set cnn = Nothing
        Set oRoot = Nothing
        Set oDomain = Nothing
        
        Exit Sub
    GetLoginIDsErrHandler:
        Select Case Err.Number
            Case Else
                MsgBox "Error in blah " & vbCrLf & vbCrLf & Err.Description, vbOKOnly + vbExclamation
                Resume GetLoginIDsExitPoint
        
        End Select
    
    End Sub
    Last edited by DinoVaught; November 21st, 2007 at 02:55 PM.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: ADO, LDAP default 1000 records??

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured