DirectorySearcher.FindAll() -should have PageSize=1000

When you are calling DirectorySearcher.FindAll() and there is  a chance to have more than 1000 records back, you must set PageSize to non-zero value, preferably 1000. Otherwise only the first 1000 records will be returned and other entries will be missed without any warning.

The names of DirectorySearcher members  and documentation is quite messy. FindAll() method should return ALL records, not the first 1000. Setting PageSize doesn't mean that you get back only single page, but triggers returning of the values into "page size" chunks transparently to you in the background. If you set SizeLimit to a value that is larger than
the server-determined default of 1000 entries, the server-determined default is used.

Thanks to Joe Kaplan's post that finally helped to find solution.

I have a simple program that imported AD users to application database. It was tested and worked fine on a few sites.

However one of our customers complained that some users were missed during import when others were imported successfully. No pattern was found what is the difference between imported and missed user accounts.

After some investigation it was noticed that only 1000 records are returned by DirectorySearcher.FindAll.  Ok, documentation describes DirectorySearcher.SizeLimit with default value is zero, which means to use the server-determined default size limit of 1000 entries. I've changed SizeLimit to 100000, but it didn't help -still only the first 1000 was returned. 
Reading further, I found that the server-determined default is used so SizeLimit is useless, if you expect  big number of results. In a few posts I found how to change the default value on the server, but there were also recommendations not to change server setting, but use paging instead. OK but how to use paging? I've started to search for code examples, expecting that some complicated coding will be required.

Finally  Joe Kaplan's post explains that only code change that required is
PageSize=1000
and all paging will happen in background.

MS should have better  DirectorySearcher documentation and implement background paging by default.

posted @ Tuesday, December 20, 2005 7:01 AM

Print

Comments on this entry:

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by JB at 2/8/2006 9:12 PM
Gravatar
Problem solved! Thank you sooooooo much for posting this solution!

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Tortured Soul at 7/15/2006 2:35 AM
Gravatar
Bhai u r God. You saved many lives...^:)^

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by TS at 9/7/2006 12:42 PM
Gravatar
Good solution. It helped me fixing search issues in my program.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Leon Zandman at 9/22/2006 3:25 PM
Gravatar
Thanks for your post. It helped me fix my problems. I agree the MSDN docs should be more clear about this issue.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by FTriana at 12/1/2006 4:11 AM
Gravatar
Thank you so much for posting this tip !!

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Abinayaa at 4/3/2007 1:57 PM
Gravatar
Thanks !!! Thanks !!! this info has helped me to solve the problem quickly....

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by M4k at 5/29/2007 1:00 AM
Gravatar
THANKS A LOT!!!

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Pruthvi at 6/22/2007 3:52 AM
Gravatar
Thanks a lot !!! At last I reached to the information which I wanted. I spent 2 Hrs on google before I reach here.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Aneesh Aravind at 7/27/2007 7:27 AM
Gravatar
I already did that. I have a different issue. My computer gets bogged down when the result set gets to ~ 1800. I set the page size to 1000. I checked the pagefile usage and found that it was more than double of what it usually is.

Did anyone else encounter this issue?

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Mow at 11/12/2007 8:58 PM
Gravatar
Try a number greater than 1000 for example 2000....

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by DeLo at 12/17/2007 5:34 AM
Gravatar
Like other responses, I searched for hours on dealing with more than 1000 objects. This did it.. thanx for sharing.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by jl at 1/9/2008 12:36 AM
Gravatar
THANKS!!

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Dave at 2/26/2008 12:07 AM
Gravatar
Thanks,Helped me as wel.I was also perplexed by this problem.It saved me a lots of time.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Talat at 7/3/2008 4:04 AM
Gravatar
Thanks, great solution!
I tried many other ways without success.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Mahfuz at 8/10/2008 4:20 PM
Gravatar
The solution is working fine for me. Thanks a lot! But it is strange that nobody is complaining about Microsoft for this stupid bug! :|

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Mike at 8/25/2008 7:36 AM
Gravatar
Thanks for finding such an easy fix to an annoying problem!

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Noah at 8/27/2008 8:26 AM
Gravatar
Thanks for this. I'll test this for my customer and see if it works.

Your comment:



 (will not be displayed)


 
 
 
Please add 6 and 8 and type the answer here:
 

Live Comment Preview:

 
«August»
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456