C# to OpenLDAP

  • Thread starter Thread starter David
  • Start date Start date
D

David

Hi all,

I have a problem. Been pulling my hair out all day with this. Had a number
of errors, but now I am so close. This is connecting to OpenLDAP on a linux
box. My app is an ASP.NET app in C#.


System.DirectoryServices.DirectoryEntry entryPC = new
System.DirectoryServices.DirectoryEntry();

entryPC.Path =
"LDAP://MyLDAPServer389/ou=pens,dc=anotes,dc=com";

string sFilter =
String.Format("(&(objectClass=pen)(description={0}))", PenIDTextBox.Text);
entryPC.AuthenticationType =
System.DirectoryServices.AuthenticationTypes.Anonymous;

System.DirectoryServices.DirectorySearcher ds = new
System.DirectoryServices.DirectorySearcher(entryPC);
ds.Filter = sFilter;

ds.SearchScope = System.DirectoryServices.SearchScope.Subtree;

System.DirectoryServices.SearchResult sr = null;

bool SRFailed = false;

try
{
sr = ds.FindOne();
}
catch(Exception ex)
{
SRFailed = true;
}


The path is correct as I can connect to it with an LDAP Browser.

When I run it, I am dropping into the catch and getting an error "The
parameter is incorrect", which is about as helpful as praying for it to
work.


Inside my ou=pens, I have a branch (an endpoint) of serialNumber=0x000....
(hex number). There are two of these. Inside these, I have various
attributes, 3 objectClass (one of them has the value "pen" and a description
attribute with the value that I am searching for.

If I put my sFilter value in my LDAP Browser search routine, then I get the
result (but only if I scan the subtree).

Absolutely any help, even if you don't know the answer but possible have
noticed something I may have missed will be helpful.

Thanks.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
Back
Top