Solved

How to Obtain return code from LDAP Directory search

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This article outlines the process to identify and resolve account lockout in an Active Directory environment.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

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