?
Solved

How to Obtain return code from LDAP Directory search

Posted on 2011-02-28
4
Medium Priority
?
306 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
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 …
Suggested Courses

770 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