2014-01-22 92 views
0

我得到這個特定的錯誤,幫助將不勝感激是什麼導致Microsoft VBScript運行時錯誤 '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 
+1

這不是一個.NET的問題;在猜測我會說openConnectionAdmin()返回Nothing。您需要查看該方法中發生的情況,可能連接字符串詳細信息是錯誤的。 – sh1rts

+0

這意味着你得到一個執行SQL的錯誤。沉默錯誤是壞主意,刪除'On Error Resume Next'行,看看你得到什麼錯誤。 **不要使用'在錯誤恢復下一個'沒有陷入錯誤**! –

回答

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每個可想到的誤差()的函數可以返回空(未檢測!),這不是一個對象,並且不能使用集被分配給一個變量。

+0

這是我的openRecordset功能'功能openRecordSet(BYVAL STRSQL,爲ByRef objConnection) \t上的錯誤繼續下一步 '\t logSQL(STRSQL) \t集openRecordset = objConnection.Execute(STRSQL) \t如果Err.Number的<> 0然後 \t \t「回覆於Err.Number的& 「 - 」 &Err.Description \t \t LOGERROR( 「ASP:openRecordset:」 &Err.Number的& 「 - 」 &Err.Description& 「:」 &STRSQL) 「\t \t呼叫displayErrorPage() \t結束如果 端功能' – user3199543

+0

這可能是值得編輯問題包括openRecordSet功能。另外,是否在調用execute時檢查objConnection對象是否爲null?我敢打賭,這將是你的問題(並由不正確的連接字符串引起)。 – Ted

相關問題