Asp classic 处理命令期间发生一个或多个错误。提供程序错误“80040e14”

Asp classic 处理命令期间发生一个或多个错误。提供程序错误“80040e14”,asp-classic,ldap,Asp Classic,Ldap,当我在经典ASP中对LDAP查询执行类似操作时,收到一个提供程序错误“80040e14” 我的代码是: <% response.Buffer = True function get_ldap_query(firstname, lastname, unit) dim ADUser, objCom, objCon, objRS ADUser = "LDAP://OU=Staff,OU=Users,DC=example,DC=internal" '

当我在经典ASP中对LDAP查询执行类似操作时,收到一个提供程序错误“80040e14”

我的代码是:

<% 
response.Buffer = True

function get_ldap_query(firstname, lastname, unit)
    dim ADUser, objCom, objCon, objRS
    ADUser = "LDAP://OU=Staff,OU=Users,DC=example,DC=internal"
    ' Make AD connection and run query'
    Set objCon = Server.CreateObject("ADODB.Connection")
    objCon.provider ="ADsDSOObject"
    objCon.Properties("User ID") = "EXAMPLE\test"
    objCon.Properties("Password") = "example"
    objCon.Properties("Encrypt Password") = TRUE
    objCon.open "Active Directory Provider"
    Set objCom = CreateObject("ADODB.Command")
    Set objCom.ActiveConnection = objCon
    objCom.CommandText = "SELECT givenName, sn, mail, telephonenumber, mobile, description, sAMAccountName, cn, UserAccountControl FROM '"+ ADUser + "' where (cn LIKE *" + firstname + "* OR cn like *" + lastname + "*) AND UserAccountControl <> 514 ORDER by cn ASC" 
    Set objRS = objCom.Execute
    Response.Write "<table>" + vbCrLf
    Do While Not objRS.EOF Or objRS.BOF
        Response.Write "  <tr>"
        Response.Write "<td>" + objRS("givenName") + "</td>"
        Response.Write "<td>" + objRS("sn") + "</td>"
        Response.Write "<td>" + objRS("mail") + "</td>"
        ' Check if field is null to avoid error'
        If IsNull(objRS.Fields("Description").Value) Then
            sDesc = ""
        else
            For Each item In objRS.Fields("description").Value
                sDesc = item + "<br>"
            Next
        end if
        Response.Write "<td>" + sDesc + "</td>"
        Response.Write "<td>" + objRS("mobile") + "</td>"
        Response.Write "<td>" + objRS("telephonenumber") + "</td>"
        if objRS("sAMAccountName") <> mid(Request.ServerVariables("AUTH_USER"), 11) then
            'If the account name held in AD is different to the one the user is logged in with, a blank cell is output. If they are the same, a link allowing the user to edit their entry is displayed'
            Response.Write "<td></td>"
        else
            Response.Write "<td><a href='entry.asp?account_name=" + objRS("sAMAccountName") + "'>Edit</a></td>"
        end if
        Response.Write "</tr>" + vbCrL
        objRS.MoveNext
        Response.Flush
    Loop
    Response.Write "</table>"
    'Clean up'
    objRS.Close
    objCon.Close
    Set objRS = Nothing
    Set objCon = Nothing
    Set objCom = Nothin
end function
%> 

我做错了什么?

问题在下面一行

objCom.CommandText = "SELECT givenName, sn, mail, telephonenumber, mobile, description, sAMAccountName, cn, UserAccountControl FROM '"+ ADUser + "' where (cn LIKE *" + firstname + "* OR cn like *" + lastname + "*) AND UserAccountControl <> 514 ORDER by cn ASC" 
名字和姓氏周围缺少单引号,应该如下所示

objCom.CommandText = "SELECT givenName, sn, mail, telephonenumber, mobile, description, sAMAccountName, cn, UserAccountControl FROM '"+ ADUser + "' where (cn LIKE '*" + firstname + "*' OR cn like '*" + lastname + "*') AND UserAccountControl <> 514 ORDER by cn ASC" 

您的代码示例也没有显示这些记录是如何设置的,因此它们可能是空的,在这种情况下,您将获得所有记录,在这种情况下,您可能返回了太多的记录。您需要添加一些逻辑来检查这两个字符串是否都是空的并正常退出,或者以某种方式限制返回的记录数。

在ASP中,要连接字符串,您可以使用符号&而不是加号+实际上@JenR,您可以同时使用这两个符号,尽管我坚持&over+,但它只是把事情弄糊涂了。@Lankymart很高兴知道——不知何故,我以前从未在实际工作中遇到过这种情况。我可以发誓这确实给我带来了问题,但这是一个足够模糊的内存,我只记得不要将+用于连接哪一行是第19行?第19行是Set objRS=objCom.Execute行
objCom.CommandText = "SELECT givenName, sn, mail, telephonenumber, mobile, description, sAMAccountName, cn, UserAccountControl FROM '"+ ADUser + "' where (cn LIKE '*" + firstname + "*' OR cn like '*" + lastname + "*') AND UserAccountControl <> 514 ORDER by cn ASC"