Microsoft KB Archive/269361

{|
 * width="100%"|

HOWTO: Work Around the Limitation that ADO MaxRecord Is Not Implemented in DS OLEDB Provider ADsDSOObject

 * }

Q269361

-

The information in this article applies to:


 * Microsoft Active Directory Service Interfaces, version 2.5
 * Microsoft Active Directory Services Interface, System Component
 * Microsoft Active Directory Services Interface, Microsoft Active Directory Client

-

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 = &quot;Provider=ADsDSOObject&quot; 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 &quot;;(objectClass=organizationalPerson)&quot; & _ &quot;;cn,adspath;subtree&quot;,, 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(&quot;ADODB.Connection&quot;) set cmd = CreateObject(&quot;ADODB.Command&quot;) set rs = CreateObject(&quot;ADODB.RecordSet&quot;)

lcConn = &quot;Provider=ADsDSOObject&quot; 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 &quot;;(objectClass=organizationalPerson)&quot; & _ &quot;;cn,adspath;subtree&quot;,, 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