Asked by:
AD fetching limits to 1000 records - how to work with PageSize property

Question
-
User-665654804 posted
All,
Our requirement goes like we have to display all the users under one LDAP. Everytime, we query with the AD and display, only 1000 records are displayed. But itseems we have more than 1000 records. If we try to modify the PageSize value to set more than 1000, it is either getting hanged or getting into trouble executing.
what and how to work with that?
Need help on how to use PageSize property as well as how to handle this above issue of displaying all the records in that LDAP Server. If any code pertaining to C# will be helpful and which can run either in Windows or Web environment.
Friday, August 22, 2008 10:31 AM
All replies
-
User1095185381 posted
You can't set PageSize to > 1000 unless it's been changed on the server. If you set it to 1000, your domain controller will objects records in sets of 1000. Are you sure it's hanging? A query that returns tens of thousands of users and processes them can run for many minutes. What do you mean "getting into trouble executing"? Are you seeing error messages? If so, what?
I suggest you start with a simple console program to get your query working and then move it to your ASP.NET code. I can't access my network at the mo but when I can I'll post some code. In the meantime, let us know what the errors/problems are exactly. And how many users you think you have.
Saturday, August 23, 2008 7:56 AM -
User-665654804 posted
You can't set PageSize to > 1000 unless it's been changed on the server. If you set it to 1000, your domain controller will objects records in sets of 1000. Are you sure it's hanging? A query that returns tens of thousands of users and processes them can run for many minutes. What do you mean "getting into trouble executing"? Are you seeing error messages? If so, what?
I suggest you start with a simple console program to get your query working and then move it to your ASP.NET code. I can't access my network at the mo but when I can I'll post some code. In the meantime, let us know what the errors/problems are exactly. And how many users you think you have.
Thanks for your valuable reply. We have more than 5000 employees in our organization. Our application is going to fetch all those Users, including some DL's also. It is like, without any filtering, simply gonna fetch all the entries in our LDAP Server. But what ever we try, we are getting only 1000 records. We identified it by searching the list for some known user, which is not available in the result.
If we have to set the pagesize property in Server, how to do that?
Errors, i will post, in my next reply as a screenshot. Troubles getting executing are those like errors, sometimes, the EXE is getting hanged. We are using it in WPF Windows based app, not in ASP.Net
Sunday, August 24, 2008 9:22 AM -
User1095185381 posted
I forgot to ask: what directory are you using? Certainly for Active Directory, 5000 users isn't a lot. Maybe my big dinner's gone to my brain but I can't figure what you mean by DL.
Only getting 1000 records usually means you haven't set the PageSize parameter. This code (C#) will get all users in your domain and display their sAMAccountName:
static void Main(string[] args)
{
string defaultNamingContext = GetDefaultNamingContext();
using (DirectorySearcher ds = new DirectorySearcher())
{
ds.Filter = "(&(objectClass=user)(objectCategory=person))";
ds.SearchScope = SearchScope.Subtree;
ds.PageSize = 1000;
using (SearchResultCollection src = ds.FindAll())
{
foreach (SearchResult sr in src)
{
Console.WriteLine("Found user: {0}", sr.Properties["sAMAccountName"][0].ToString());
}
}
}
Console.WriteLine("\r\nPress a key to continue...");
Console.ReadKey(true);
}
private static string GetDefaultNamingContext()
{
using (DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE"))
{
return rootDSE.Properties["defaultNamingContext"].Value.ToString();
}
}If you run the code and watch the display, you'll notice it pause every so often - if you add a counter to the display, you'll see that it pauses every 1000 users. This is the way ActiveDirectory works if you activate paging (by setting PageSize to 1000). You can set paging to less than 1000 and get a more responsive application, if you want.
I seem to have confused you with my original reply. When I was talking about the server setting, I was trying to say that you can make the server return more than 1000 objects at a time but all this does is increase the size of the page - you still need paging to make it work and since your admin guys probably won't want to do it I wouldn't worry about it.
I suggest you start by getting your query working in a basic console app, then transfer the working class(es) into your app proper.
Sunday, August 24, 2008 3:44 PM -
User-888716373 posted
Can you please provide java code to do the same,Thank you.Wednesday, August 12, 2020 3:22 PM