首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >是什么导致Microsoft VBScript运行时错误“800a01a8”

是什么导致Microsoft VBScript运行时错误“800a01a8”
EN

Stack Overflow用户
提问于 2014-01-22 02:28:46
回答 1查看 1.4K关注 0票数 0

我得到了这个具体的错误,非常感谢你的帮助

Microsoft VBScript运行时错误“800a01a8” 所需对象:“openRecordSet(.)” /admin/用户/联属公司/process.asp,第47行

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

代码语言:javascript
运行
复制
<%  
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
EN

回答 1

Stack Overflow用户

发布于 2014-01-22 08:21:24

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

代码语言:javascript
运行
复制
>> Set v = New RegExp
>>                         [no news here are good news]
>> Set v = "a"
>>
Error Number:       424
Error Description:  Object required

所以请检查您的openRecordset函数。它是否通过执行

代码语言:javascript
运行
复制
Set openRecordset = ....

(标记Set)对于给定的参数?

更新wrt注释:

这个测试脚本:

代码语言:javascript
运行
复制
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

产出:

代码语言:javascript
运行
复制
TypeName(openConnectionAdmin()):  Connection
TypeName(openRecordset(...))   :  Empty
... Microsoft VBScript runtime error: Object required: 'openRecordset(...)'

代码语言:javascript
运行
复制
TypeName(openConnectionAdmin()):  Nothing
TypeName(openRecordset(...))   :  Empty
... Microsoft VBScript runtime error: Object required: 'openRecordset(...)'

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21273053

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档