簡體   English   中英

是什么導致Microsoft VBScript運行時錯誤'800a01a8'

[英]What's causing Microsoft VBScript runtime error '800a01a8'

我收到此特定錯誤,將不勝感激

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

該錯誤通常是由於使用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分配給變量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM