Solved

How to Obtain return code from LDAP Directory search

Posted on 2011-02-28
4
300 Views
Last Modified: 2012-05-11
I have working LDAP search code for both AD and SunOne (ok, Oracle now).   And it all seems to work fine.   However, there is a new requirement and I'm scratching my head.

How does one obtain the LDAP return code such as documented on http://msdn.microsoft.com/en-us/library/aa367014(VS.85).aspx ?

A code snippet is attached.  
I would think that the LDAP return code is found either in the SearchResultCollection or obtained through exception handling but I'm drawing a blank.

Thoughts?

Thank you.
With dirSearcher
            .Filter = String.Concat("(&(objectClass=person)(uid=", thisUid, "))")
            Dim queryResults As SearchResultCollection
            Dim thisResult As SearchResult
            Try
                queryResults = dirSearcher.FindAll
                _nbrFound = queryResults.Count
                For Each thisResult In queryResults
                    ' Obtain values here
                Next

            Catch ex As Exception
                _ErrorText = ex.Message
            End Try

Open in new window

0
Comment
Question by:RichardKline
  • 2
  • 2
4 Comments
 
LVL 19

Expert Comment

by:Daniel Van Der Werken
ID: 34999634
I'm pretty sure you'll have to grab the error out of the exception.  The .NET Framework methods like .FindAll don't return an error code and it doesn't seem that any of the classes contain an error code property.

I just ran a test and did this:
dirSearcher.Filter = "ABCD";

Then, in the exception, I got this for ex.Message:
The ABCD search filter is invalid.

Which directly relates to:
LDAP_FILTER_ERROR
0x57 The search
 
0
 
LVL 1

Author Comment

by:RichardKline
ID: 34999916
Understood.   And ex.message has served well for a few years now.    It states in reasonable detail what's going on and, once tweaked a bit, can be presented directly to the user.   However, the new requirement mandates that applications display canned generic messages based upon the LDAP return code.   It will probably be implemented via hashtable or a Select case block...

Leaving aside the much desired diatribe on advisability and wisdom level, that is the gameplan.

So, one way would be to to assume a LDAP return code based upon an examination of ex.message and then proceed from there.   I was hoping for something else.

0
 
LVL 19

Accepted Solution

by:
Daniel Van Der Werken earned 500 total points
ID: 34999979
The only other thing I can think of is to directly PInvoke the Windows binaries that handle these C++ functions themselves.  You'd still have to set up constants for all of the return codes, but you'd be able to call the C++ functions directly.  At that point, you're basically making the C++ call.

Lots of Marshalling fun though.
0
 
LVL 1

Author Comment

by:RichardKline
ID: 35000037
yeah.... I'm going to leave this question open for a short while in the hope that ...  well just hope.   But I feel that 'tis unlikely anyone will come up with a "magic bullet".

Thank you.

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Do you have users whose passwords are expiring and they are constantly calling you?  Well I sure did and needed a way to put an end to this.  We have a lot of remote users which would not be notified that their passwords were expiring since they wer…
Introduction You may have a need to setup a group of users to allow local administrative access on workstations.  In a domain environment this can easily be achieved with Restricted Groups and Group Policies. This article will demonstrate how to…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now