How to work around the limitation that ADO MaxRecord is not implemented in DS OLEDB provider ADsDSOObject (269361)



The information in this article applies to:

  • Microsoft Active Directory Services Interface, System Component
  • Microsoft Active Directory Services Interface, Microsoft Active Directory Client

This article was previously published under Q269361

SUMMARY

The MaxRecord method off of an ADO Recordset object is not implemented in the Directory Services (DS) OLEDB provider ADsDSOObject.

This article provides a Microsoft Visual Basic and a Microsoft Visual Basic Script sample that show how you can work around this limitation.

MORE INFORMATION

The following code samples implement these steps:
  1. Set the PageSize to the number of records that you want returned.
  2. Set the CacheSize to the PageSize.
  3. Set the CursorType to adOpenStatic client-side cursor.
  4. Set the query string (either a Lightweight Directory Access Protocol [LDAP] or SQL dialect query can be used).
  5. Set the Absolute Page to 1 (so you end up on the first page).
  6. Set the rs.Filter to the number of records in the current cache.

Visual Basic Sample Code

Dim cn As New ADODB.Connection, cmd As New ADODB.Command, rs As New ADODB.Recordset

Dim lcConn As String
Dim i As Integer
Dim j As Integer


lcConn = "Provider=ADsDSOObject"
With cn
    .Open lcConn
End With


With rs
   
    Set .ActiveConnection = cn
    .CursorLocation = adUseClient
    .CursorType = adOpenStatic
    .LockType = adLockOptimistic
    .PageSize = 3 '<--- this is the value to change for how many records to return.
    .CacheSize = .PageSize
    .Open "<LDAP://ServerName>;(objectClass=organizationalPerson)" & _
        ";cn,adspath;subtree", , adOpenStatic, adLockReadOnly, adCmdText

    .AbsolutePage = 1
    .Filter = adFilterFetchedRecords
End With

For i = 0 To rs.RecordCount - 1
    For j = 0 To rs.Fields.Count - 1
        Debug.Print rs.Fields(j).Value,
    Next
    Debug.Print
    rs.MoveNext
Next

				

Visual Basic Scripting Sample Code

const adUseClient=3
const adOpenStatic = 3
const adLockOptimistic = 3
const adLockReadOnly = 1
const adCmdText = 1
const adFilterFetchedRecords = 3

Dim cn
dim cmd 
dim rs
Dim lcConn

Dim i
Dim j

set cn = CreateObject("ADODB.Connection")
set cmd = CreateObject("ADODB.Command")
set rs = CreateObject("ADODB.RecordSet")

lcConn = "Provider=ADsDSOObject"
With cn
    .Open lcConn
End With


With rs
   
    Set .ActiveConnection = cn
    .CursorLocation = adUseClient
    .CursorType = adOpenStatic
    .LockType = adLockOptimistic
    .PageSize = 3 '<--- this is the value to change for how many records to return.
    .CacheSize = .PageSize
    .Open "<LDAP://maxvdc2>;(objectClass=organizationalPerson)" & _
        ";cn,adspath;subtree", , adOpenStatic, adLockReadOnly, adCmdText

    .AbsolutePage = 1
    .Filter = adFilterFetchedRecords
End With

For i = 0 To rs.RecordCount - 1
    For j = 0 To rs.Fields.Count - 1
        WScript.Echo rs.Fields(j).Value
    Next
    WScript.Echo
    rs.MoveNext
Next
				

REFERENCES

For more information on Active Directory Service Interfaces (ADSI), see the following Microsoft Web sites:

http://www.microsoft.com/adsi

http://www.msdn.microsoft.com/library/default.asp (In the left frame, click to expand Platform SDK Documentation, expand Networking and Directory Services, and then expand Directory Services to get to ADSI.)


Modification Type:MajorLast Reviewed:5/20/2005
Keywords:kbDSWADSI2003Swept kbhowto kbMsg KB269361