是什么导致Microsoft VBScript运行时错误'800a01a8'

时间:2014-01-22 02:28:46

标签: vbscript asp-classic runtime-error

我收到此特定错误,将不胜感激

  

Microsoft VBScript运行时错误'800a01a8'

     

需要对象:'openRecordSet(...)'

     

/admin/users/affiliates/process.asp,第47行

第47行是Set objRecordset = openRecordset(strSQL, objConnection)

<%  
SetUserLevel(" 2 ")

If (InStr(Request.ServerVariables("HTTP_REFERER"), "://jim/admin/users/affiliate") = 0) Then
    Response.Redirect( "/admin/users/affiliate/" )
End If

Dim objConnection, objRecordset, strSQL, Affiliate_ID

If (IsEmpty(Request.Form("Affiliate_ID")) Or RTrim(Request.Form("Affiliate_ID")) = "") Then
    Affiliate_ID = 0
Else
    Affiliate_ID = prepareSQL(Request.Form("Affiliate_ID"))
End If

strSQL = "EXEC sp_User_Add_Affiliate " & _
        Session("User_ID") & ", '" & _
        prepareSQL(Request.Form("First_Name")) & "', '" & _
        prepareSQL(Request.Form("Middle_Initial")) & "', '" & _
        prepareSQL(Request.Form("Last_Name")) & "', '" & _
        prepareSQL(Request.Form("Email_Address")) & "', '" & _
        Request.ServerVariables("REMOTE_ADDR") & "', " & _
        Session.SessionID & ", '" & _
        prepareSQL(Request.Form("Address_1")) & "', '" & _
        prepareSQL(Request.Form("Address_2")) & "', '" & _
        prepareSQL(Request.Form("City")) & "', '" & _
        prepareSQL(Request.Form("State")) & "', '" & _
        prepareSQL(Request.Form("Zip")) & "', '" & _
        prepareSQL(Request.Form("Country")) & "', '" & _
        prepareSQL(Request.Form("Phone")) & "', '" & _
        prepareSQL(Request.Form("Phone_Extension")) & "', '" & _
        prepareSQL(Request.Form("Fax")) & "', '" & _
        prepareSQL(Request.Form("Company")) & "', '" & _
        prepareSQL(Request.Form("Pay_To")) & "', '" & _
        prepareSQL(Request.Form("Tax_ID")) & "', '" & _
        prepareSQL(Request.Form("Tax_ID_Type")) & "', '" & _
        prepareSQL(Request.Form("Tax_Class")) & "', " & _
        Affiliate_ID & "," & _
        Request.Form("ID") & "," & _
        Request.Form("Approved")

Set objConnection   = openConnectionAdmin()
Set objRecordset    = openRecordset(strSQL, objConnection)

If objRecordset("Error") = "1" Then
    Response.Write objRecordset("Data")
    Response.End
End If

objRecordset.Close

Set objRecordset    = Nothing
Set objConnection   = Nothing

Response.Redirect ( "/admin/users/affiliates/" ) %>

Function openRecordSet(ByVal strSQL, ByRef objConnection) 
    On Error Resume Next 
    '   logSQL(strSQL) 
    Set openRecordset = objConnection.Execute(strSQL) 
    If err.Number <> 0 Then 
          'Response.Write Err.Number & " - " & Err.Description logError("ASP: openRecordset: " & Err.Number & " - " & Err.Description & ": " & strSQL) 
    '    Call displayErrorPage() 
    End If 
End Function

1 个答案:

答案 0 :(得分:0)

错误通常是由于使用Set来指示将对象赋值给变量,但是具有正确值的非对象:

>> Set v = New RegExp
>>                         [no news here are good news]
>> Set v = "a"
>>
Error Number:       424
Error Description:  Object required

请检查您的openRecordset功能。它是否通过执行

返回记录集
Set openRecordset = ....

(标记Set)给定参数?

更新wrt评论:

此测试脚本:

Option Explicit

' How to test the type of a function's return value that should
' be an object but sometimes isn't. You can't assign the return value
' to a variable because of VBScript's disgusting "Set".
WScript.Echo "TypeName(openConnectionAdmin()): ", TypeName(openConnectionAdmin())
WScript.Echo "TypeName(openRecordset(...))   : ", TypeName(openRecordset("", objConnection))

' Trying to create a connection and a recordset
Dim objConnection : Set objConnection = openConnectionAdmin()
Dim objRecordset  : Set objRecordset  = openRecordset("", objConnection)

Function openConnectionAdmin()
' Set openConnectionAdmin = CreateObject("ADODB.CONNECTION")
  Set openConnectionAdmin = Nothing
End Function

' After removing the comments: Obviously this is a function that
' hides all errors; the programmer should be fed to the lions.
Function openRecordSet(ByVal strSQL, ByRef objConnection)
    On Error Resume Next
    Set openRecordset = objConnection.Execute(strSQL)
End Function

输出:

TypeName(openConnectionAdmin()):  Connection
TypeName(openRecordset(...))   :  Empty
... Microsoft VBScript runtime error: Object required: 'openRecordset(...)'

TypeName(openConnectionAdmin()):  Nothing
TypeName(openRecordset(...))   :  Empty
... Microsoft VBScript runtime error: Object required: 'openRecordset(...)'

显示:通过隐藏openRecordset()中的每个可能的错误,该函数可以返回Empty(未检测到!),它不是一个对象,也不能通过使用Set分配给变量。