Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Having problem accessing AD using SQL

18 views
Skip to first unread message

Roland Smith

unread,
Oct 20, 2003, 3:42:18 PM10/20/03
to
I have created an .ASP webapp that allows searching AD for users and then
displaying information about them. The problem I am having is that some
people have an apostrophe in their last name. So if I were to try searching
for O'Hara I get this error:

Provider error '80040e14'
One or more errors occurred during processing of command.

It is getting a SQL syntax error because part of the SQL statement looks
like this:

" AND sn = 'O'Hara' "

I have tried using double quotes but that gives a syntax error as well.
Below is a sample vbscript that uses SQL to search all users with a name of
Smith. If you can get it to work with O'Hara please let me know.

Thanks,
Roland


Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_SCOPE_SUBTREE = 2
Const adStateOpen = 1
Dim objDSE, objCon, objCmd, objRS, objUsr, strDNC

' Create Active Directory connection object
Set objCon = CreateObject("ADODB.Connection")
objCon.Provider = "ADsDSOObject"
objCon.Open "ADQuery"

' Create Active Directory command object
Set objCmd = CreateObject("ADODB.Command")
Set objCmd.ActiveConnection = objCon

' Create Active Directory SQL statement
Set objDSE = GetObject("LDAP://RootDSE")
strDNC = "LDAP://" & objDSE.Get("defaultNamingContext")
objCmd.CommandText = "SELECT ADsPath," & _
" userAccountControl" & _
" FROM '" & strDNC & "'" & _
" WHERE objectClass = 'user'" & _
" AND objectCategory = 'person'" & _
" AND sn = 'Smith'" & _
" ORDER BY displayName"
objCmd.Properties("searchscope") = ADS_SCOPE_SUBTREE

' Execute Active Directory SQL statement
Set objRS = objCmd.Execute

' Process active user accounts
While Not objRS.EOF
intUAC = objRS.Fields("userAccountControl")
If intUAC AND ADS_UF_ACCOUNTDISABLE Then
Else
strADsPath = objRS.Fields("ADsPath")
Set objUsr = GetObject(strAdsPath)
WScript.Echo objUsr.sAMAccountName & " " & objUsr.displayName
End If
objRS.MoveNext
Wend

' Destroy objects
Set objDSE = Nothing
Set objCon = Nothing
Set objCmd = Nothing
Set objRS = Nothing
Set objUsr = Nothing


Shahir A. Ahang

unread,
Oct 20, 2003, 5:08:12 PM10/20/03
to
try this:

" AND sn = ""O""Hare"""

I believe ' in VBScript (ASP) is represented by "".

Shahir

"Roland Smith" <rsm...@cvps.com> wrote in message
news:eWJHHJ0l...@TK2MSFTNGP09.phx.gbl...

Roland Smith

unread,
Oct 21, 2003, 8:06:29 AM10/21/03
to
As I said in my post, I have already tried that and it gets an error also.

"Shahir A. Ahang" <thisis...@thisisbsintrinsic.thisisbsnet> wrote in
message news:uNph640l...@tk2msftngp13.phx.gbl...

Roland Smith

unread,
Oct 21, 2003, 9:20:34 AM10/21/03
to
I figured it out myself. I have to use double single quotes:

" AND sn = 'O''Hara' "

"Shahir A. Ahang" <thisis...@thisisbsintrinsic.thisisbsnet> wrote in
message news:uNph640l...@tk2msftngp13.phx.gbl...

0 new messages