473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

LDAP Search Results

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
4 22553
>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
>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
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
>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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bjoern Eberth | last post by:
Hi there, i have a few problems accessing a ldap server with the java api JNDI. I am able to get attributes with the following code: ...
1
by: Dave | last post by:
Could someone fix this for me please. The last bit i cant figure out is the last line in the sub. Results.SetDataBinding(myTable.DefaultView, "") Thanks Dave ...
2
by: Neil via .NET 247 | last post by:
I have some code vb.net winforms, that works fine most of the time but stops working occasionally such as right now. The code is this Dim objDE As New DirectoryEntry("LDAP://" & DomainName) Dim...
2
by: Rosanne Rohana | last post by:
I'm trying for return user info (first name, last name, etc.) from a Netscape 4.16 LDAP server using the System.DirectoryServices. I'm able to get authenticated successfully, but when I attempt to...
2
by: rufpirat | last post by:
Hello I'm in the middle of trying to build an "AD phone book", and this being my first try at asp.net, I have a few questions that I hope some of you might be able to help with: 1. Is it...
2
by: Steve JORDI | last post by:
Hi, I'm checking a user identity on a secure LDAP server using the following code: $ldapconn = ldap_connect("ldaps://myserver.mycompany.ch", 636 ) or die( "Can't connect to LDAP" ) ; ...
10
by: Cruelemort | last post by:
All, I am hoping someone would be able to help me with a problem. I have an LDAP server running on a linux box, this LDAP server contains a telephone list in various groupings, the ldif file of...
6
by: hotani | last post by:
I am attempting to pull info from an LDAP server (Active Directory), but cannot specify an OU. In other words, I need to search users in all OU's, not a specific one. Here is what works: con...
2
by: Lars | last post by:
Hi I got some programming experience and I recently started looking into Python. I've read much of the tutorial from 2.6 documentation. But it was more interesting to get started on something I...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.