Solved

How to Obtain return code from LDAP Directory search

Posted on 2011-02-28
4
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 20

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 20

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A hard and fast method for reducing Active Directory Administrators members.
Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

726 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