Hi,

I usually only participate in the C/C++ forum but i guess desperate times need desperate measures.

Well, i am trying to query an LDAP through DirectoryServices but can't seem to get it right and need ur help in the matter.

Here's the code i am using..

strUID = Request.ServerVariables("HTTP_UID")
 
Dim Entry As System.DirectoryServices.DirectoryEntry
Entry = New DirectoryEntry[URL]ldap://myserver:401/ou=people,o=org[/URL], "uid=myid,o=org", "pwd123")
Dim Search As DirectorySearcher = New DirectorySearcher(Entry)
Search.Filter = "(micid=" & strUID & ")"
Search.PropertiesToLoad.Add("givenname")
Search.PropertiesToLoad.Add("sn")
Search.PropertiesToLoad.Add("telephoneNumber")
Search.PropertiesToLoad.Add("mail")
Dim Results As SearchResult = Search.FindOne()
strfname = Results.Properties("givenname")(0).ToString()

The error i am getting is :
The parameter is incorrect.


I got a hunch that the user id i am using i.e uid=myid,o=org
is the cause of the problem as the server is taking it as more than one parameter.
But don't know how to fix it..

Can anybody help..??

Thanks a lot..

This looks like it might be a problem:

Entry = New DirectoryEntryldap://myserver:401/ou=people,o=org, "uid=myid,o=org", "pwd123")

I'm going to guess that your code actually includes the '(' character between "DirectoryEntry" and "ldap...".
The LDAP URL that you provided contains a comma. So, if your not putting this value in quotes ("") then the function will think its receiving 4 parameters
#1 - ldap://myserver:401/ou=people
#2 - o=org
#3 - uid=myid,o=org
#4 - pwd123


Hope this helps,
Andrew.

i guess that was a typing mistake on my part.
its actually like this:

Entry = New DirectoryEntry("[URL]ldap://myserver.com:401/ou=people,o=org[/URL]", "uid=myid,o=org", "pwd123")

i guess then the parameter count remains three as required.

Hi,
Thanks i fiugured that out myself..

Let me give the solution fo all those who need it in the future.

i had to set the authentication type as
AuthenticationTypes.FastBind
in order to make it work..

But don't know why.

Can anyone give me a reason.

One thing more. I am having trouble with getting the values.

If the "sn" property for a person doesn't exist in the directory, i get an exception while taking its value in the variable. The exception is:Null reference exception.

How do i curb this one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.