简体   繁体   中英

What's causing Microsoft VBScript runtime error '800a01a8'

I am getting this specific error, help would be appreciated

Microsoft VBScript runtime error '800a01a8'

Object required: 'openRecordSet(...)'

/admin/users/affiliates/process.asp, line 47

Line 47 is 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

The error typically is caused by using Set to indicate assignment of an object to a variable, but having a non-object for the right value:

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

So check your openRecordset function. Does it return a recordset by executing

Set openRecordset = ....

(mark the Set ) for the given parameters?

Update wrt comments:

This test script:

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

output:

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

or

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

shows: By hiding every conceivable error in openRecordset() the function can return Empty (undetected!), which isn't an object and can't be assigned to a variable by using Set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM