I am trying to create a proof of concept to show how to connect to an LDAP
server and how to search for values but I do not get anywhere. Here is what I
have so far:
Dim objEntry As DirectoryEntry
Dim objSearcher As DirectorySearcher
Try
objEntry = New DirectoryEntry("ldap://www.openldap.com/dc=OpenLDAP,dc=org",
Nothing, Nothing, AuthenticationTypes.Anonymous)
objSearcher = New DirectorySearcher(objEntry, "(ou=People)")
objSearchResult = objSearcher.FindOne()
If Not objSearchResult Is Nothing Then
'Do something
End If
Catch ex As Exception
result.Text = ex.Message & vbNewLine & ex.Source
End Try
My code fails at the line:
objSearchResult = objSearcher.FindOne()
with the unhelpfu error of Unknown error (0x80005000)
As you can see I use the www.openldap.com directory and I can connect
anonymously using the Softeerra LDAP Browser 2.5
Any help would be greatly appreciated
PS: I know there is already a similar thread (http://forums.asp.net/thread/1028020.aspx) but none of the suggested solutions work. Plus the proof of concept is a windows app, not a web app
Never mind - I might have figured it out. The problem was the following line:
objEntry = New DirectoryEntry("ldap://www.openldap.com/dc=OpenLDAP,dc=org",Nothing, Nothing, AuthenticationTypes.Anonymous)
No, the address is correct but it seems that the directoryEntry does not like it when the ldap:// part not all upper case. The entire code worked as soon as I changed i to:
LDAP://www.openldap.com/dc=OpenLDAP,dc=org. Plus the parameters for the user name and password should be set to an empty string and not nothing but I left them usually out anyway.
But still, let me know if you see any other issues that I did not catch at this point.
Thanks
Marked as answer by mbanavige on Apr 08, 2013 10:52 AM
Yep, the provider is case sensitive as it tells ADSI how to behave - there are other ones too (e.g. WinNT, GC, Ads, IIS, NDS, etc.). The most important one is LDAP really.
DirectoryServices error messages are seldomly funny ;-(
You can try to access the NativeObject of the DirectoryEntry to determine if authentication was successful. Try something like:
Dim value As Object
value = objEntry.NativeObject
If you do this right after you've created your DirectoryEntry (objEntry) then the value = ... should succeed if you are authenticated correctly, otherwise it will throw an Exception. If you start with this, then you should be able to determine if it is
related to authentication problems.
If this post was useful to you, please mark it as answer. Thank you!
rimmey14
Member
15 Points
3 Posts
LDAP Problem with .NET - Unknown error (0x80005000)
Sep 14, 2006 11:15 PM|LINK
I am trying to create a proof of concept to show how to connect to an LDAP
server and how to search for values but I do not get anywhere. Here is what I
have so far:
Dim objEntry As DirectoryEntry
Dim objSearcher As DirectorySearcher
Try
objEntry = New DirectoryEntry("ldap://www.openldap.com/dc=OpenLDAP,dc=org",
Nothing, Nothing, AuthenticationTypes.Anonymous)
objSearcher = New DirectorySearcher(objEntry, "(ou=People)")
objSearchResult = objSearcher.FindOne()
If Not objSearchResult Is Nothing Then
'Do something
End If
Catch ex As Exception
result.Text = ex.Message & vbNewLine & ex.Source
End Try
My code fails at the line:
objSearchResult = objSearcher.FindOne()
with the unhelpfu error of Unknown error (0x80005000)
As you can see I use the www.openldap.com directory and I can connect
anonymously using the Softeerra LDAP Browser 2.5
Any help would be greatly appreciated
PS: I know there is already a similar thread (http://forums.asp.net/thread/1028020.aspx) but none of the suggested solutions work. Plus the proof of concept is a windows app, not a web app
rimmey14
Member
15 Points
3 Posts
Re: LDAP Problem with .NET - Unknown error (0x80005000)
Sep 15, 2006 04:36 AM|LINK
Never mind - I might have figured it out. The problem was the following line:
objEntry = New DirectoryEntry("ldap://www.openldap.com/dc=OpenLDAP,dc=org",Nothing, Nothing, AuthenticationTypes.Anonymous)
No, the address is correct but it seems that the directoryEntry does not like it when the ldap:// part not all upper case. The entire code worked as soon as I changed i to: LDAP://www.openldap.com/dc=OpenLDAP,dc=org. Plus the parameters for the user name and password should be set to an empty string and not nothing but I left them usually out anyway.
But still, let me know if you see any other issues that I did not catch at this point.
Thanks
dunnry
Star
9098 Points
1806 Posts
Re: LDAP Problem with .NET - Unknown error (0x80005000)
Sep 15, 2006 03:35 PM|LINK
Weblog
The Book
LDAP Programming Help
venkatzeus
Participant
1633 Points
1022 Posts
Re: LDAP Problem with .NET - Unknown error (0x80005000)
Mar 19, 2008 10:13 AM|LINK
Hi..
Please check this link: http://support.microsoft.com/default.aspx?scid=kb;en-us;329986
Hope this helps for the Unknown error (0x80005000) Thank you
johram
All-Star
28531 Points
3567 Posts
Re: LDAP Problem with .NET - Unknown error (0x80005000)
Mar 26, 2008 10:52 PM|LINK
DirectoryServices error messages are seldomly funny ;-(
You can try to access the NativeObject of the DirectoryEntry to determine if authentication was successful. Try something like:
If you do this right after you've created your DirectoryEntry (objEntry) then the value = ... should succeed if you are authenticated correctly, otherwise it will throw an Exception. If you start with this, then you should be able to determine if it is related to authentication problems.dr.maqk
Participant
974 Points
235 Posts
Re: LDAP Problem with .NET - Unknown error (0x80005000)
Feb 04, 2010 09:19 AM|LINK
Absolutely correct, this post is the ultimate answer, same thing happened with me and as soon i changed it to LDAP, every thing worked.
Thanks for your help rimmey
LDAP Directory Services C#
Mark as
My .Net Blog: DotNetExperience
deepak kumar...
Member
20 Points
9 Posts
Re: LDAP Problem with .NET - Unknown error (0x80005000)
Feb 11, 2010 05:22 AM|LINK
objEntry = New DirectoryEntry("ldap://www.openldap.com/dc=OpenLDAP,dc=org",
Nothing, Nothing, AuthenticationTypes.Anonymous)
objSearcher = New DirectorySearcher(objEntry, "(ou=People)")
objSearchResult = objSearcher.FindOne()
If Not objSearchResult Is Nothing Then
'Do something
End If
The Problem with the above code is The Connection string Your Using and Serach Filter
Important Dont ever use small case for ldap,Use LDAP
ldap://www.openldap.com/dc=OpenLDAP,dc=org
Give Like This LDAP://IPadress of Domain Controller or Fully Qualified Domain/dc=OpenLDAP,dc=org",USerId,Password,AuthenticationTypes.Secure
ex:LDAP://172.16.3.2/dc=OpenLDAP,dc=org",USerId,Password,AuthenticationTypes.Secure
@Note:Give Service Account Userid or USerID which has access to Domain Controller and Password of the Account
Dim adSearcher As New DirectorySearcher(adEntry)
adSearcher.Filter = "(&(objectClass=user)(sAMAccountName=" & LoginID & "))"
After the above code,load the Properpties Which u Need.
objSearchResult = adSearcher.FindOne()
LoginID is Give the UserId Which you Gave in above DirectoryEntry.