Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Using Like in SQL statement in LDAP Query

Posted on 2007-10-04
3
Medium Priority
?
4,370 Views
Last Modified: 2013-12-19
Hi,

Im writing some ASP code to retrieve all users from Active Directory in our domain. Here's what works:

objCommand.CommandText = "SELECT name FROM 'GC://" & strDomainDN & "' WHERE " &_
    "objectClass='user' AND objectCategory='person' ORDER BY name"

Now, I addes a simple textbox where users can enter the name they are searching for. Eventually the query looks like this:

objCommand.CommandText = "SELECT name FROM 'GC://" & strDomainDN & "' WHERE " &_
    "objectClass='user' AND objectCategory='person'  AND name Like '%engels%' ORDER BY name"

This doesn't work. I tried replacing the % by *, but same result.

However, when I don't use LIKE in the statement and just enter the full name, the statement works and I get a result. Here's what works:

objCommand.CommandText = "SELECT name FROM 'GC://" & strDo"mainDN & "' WHERE " &_
     "objectClass='user' AND objectCategory='person' AND name = 'pascal engels' ORDER BY name"

So it seems I can't use LIKE in statements sent to an LDAP server. Is that correct? Or is there an alternative way in doing this?

Thanks in advance :-)
0
Comment
Question by:techteamane
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 20012760
this should work:

objCommand.CommandText = "SELECT name FROM 'GC://" & strDomainDN & "' WHERE " &_
    "objectClass='user' AND objectCategory='person'  AND name = '*engels*' ORDER BY name"

0
 

Author Comment

by:techteamane
ID: 20012886
This actually does work! I was realy focused on the LIKE word, cause I use it in SQL a lot...

Thx for the help :-)
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20012889
glad I could help
0

Featured Post

Industry Leaders: 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

What we learned in Webroot's webinar on multi-vector protection.
Scripts are great for performing batch jobs against users, however sometimes the GUI is all you need.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

571 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