Using Like in SQL statement in LDAP Query

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 :-)
techteamaneAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
this should work:

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

0
 
techteamaneAuthor Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
glad I could help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.