Solved

How to Obtain return code from LDAP Directory search

Posted on 2011-02-28
4
301 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 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
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 …

930 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

10 Experts available now in Live!

Get 1:1 Help Now