By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,564 Members | 834 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,564 IT Pros & Developers. It's quick & easy.

LDAP Search Results

P: n/a
Why does my LDAP query from a C# console app limit its results to 1000? When
I run the same query from a vb script I get over 6000 results. I have tried
to set the SearchRequest.SizeLimit to a value grater than the expected
results and still only get 1000 records. I did notice that in the
LdapConnection constructor I was required to specify the target server where
in the vbs I simply passed an LDAP query to the ADSDSOObject provider. Does
this have something to do with my result set?
Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
>Why does my LDAP query from a C# console app limit its results to 1000?

That's by design - you can get around it by explicitly specifying a
"page size" - in that case, the LDAP server will send you the results
in chunks of "page size" items at a time.

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
Nov 17 '05 #2

P: n/a
>Why does my LDAP query from a C# console app limit its results to 1000?

That's by design - you can get around it by explicitly specifying a
"page size" - in that case, the LDAP server will send you the results
in chunks of "page size" items at a time.

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
Nov 17 '05 #3

P: n/a
Okay, I found an example of using paged serches in the MSDN Library for
VS2005. I copied the paged search section of the code and modified to fit
out AD structure...

---code copy

static void Main(string[] args)
{
//connect to domain controller
LdapConnection ldapConnection = new LdapConnection("DC1.dot.state.az");

//set filter options
string targetOU = "DC=dot,DC=state,DC=az";string ldapSearchFilter =
"objectClass=computer";
string[] attributesToReturn = { "name" };
int pageSize = 5;

PageResultRequestControl pageRequestControl = new
PageResultRequestControl(pageSize);
PageResultResponseControl pageResponseControl;
SearchResponse searchResponse;

// create a search request: specify baseDn, ldap search filter, attributes
to return and scope of the search
SearchRequest searchRequest = new SearchRequest(targetOU, ldapSearchFilter,
SearchScope.Subtree, attributesToReturn);
searchRequest.Controls.Add(pageRequestControl); //adds the page request
control

int count;

while (true)
{
searchResponse = (SearchResponse)ldapConnection.SendRequest(searchR equest);
Console.WriteLine("\r\nPage: " + searchResponse.Entries.Count + " entries:");

//display the entries in this page
count = 0;
foreach (SearchResultEntry entry in searchResponse.Entries)
{
// retrieve a specific attribute
DirectoryAttribute attribute = entry.Attributes["name"];
Console.WriteLine(++ count + " " + attribute.Name + " = " + attribute[0]);
}
//retrieve the cookie
if (searchResponse.Controls.Length != 1 || !(searchResponse.Controls[0] is
PageResultResponseControl))
{
Console.WriteLine("The server did not return a PageResultResponseControl
as expected.");
return;
}
pageResponseControl = (PageResultResponseControl)searchResponse.Controls[0];

//if responseControl.Cookie.Length is 0 then there are no more pages to
retrieve so break the loop
if (pageResponseControl.Cookie.Length == 0) break;
pageRequestControl.Cookie = pageResponseControl.Cookie;
}
Console.WriteLine("Complete.");

--end

This still only returns one page of data with the size limit I set but no
more than 1000.

I set a break point steped through the code. On the first pass, when their
should be more pages waiting, this line of code "if
(pageResponseControl.Cookie.Length == 0) break;" evaluates to true and the
code breakes out of the loop.

What am I missing?

Thanks!

"Marc Scheuner [MVP ADSI]" wrote:
Why does my LDAP query from a C# console app limit its results to 1000?


That's by design - you can get around it by explicitly specifying a
"page size" - in that case, the LDAP server will send you the results
in chunks of "page size" items at a time.

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch

Nov 17 '05 #4

P: n/a
>This still only returns one page of data with the size limit I set but no
more than 1000.

What am I missing?


I'm sorry, I'm not intimately familiar with the "low-level" LDAP API
(only working from .NET on the System.DirectoryServices level), and
quite honestly, I don't see what's wrong with your code here.

Maybe someone else out there has more knowledge of the low-level LDAP
interfaces and can chip in?

Marc
Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.