Windows Server 2012 / IIS8 中的经典 ASP 错误

Classic ASP error in Windows Server 2012 / IIS8

我最近不得不将(继承的)旧经典 ASP VBScript 报告网站从 windows 服务器 2003 迁移到 windows 服务器 2012。

在弄乱 AppPool 以使其使用 32 位模式并设置父路径之后,我已经能够让应用程序运行。

但是,以下页面目前正在抛出此错误:

Microsoft VBScript runtime error '800a01a8'

Object required: ''

/Dashboard/modules/Monthly_Report/footfall/Save_Session_Variables_Stock.asp, line 69

页面后面的代码是

<!--#include file="../../../../Connections/Dashboard_Connection.asp" -->
<%
Session.LCID=2057
'Session("strMonthly_Site")=trim(request("select_site"))
''xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'Set the search screen variables to be nothing
Session("strCategory_Lookup")=""
Session("strSearch_String")=""

'*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
'Get the market code based on the site
'*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
DIM rsGet_Market
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open strConnection

'Get the Site Level_Code
Session("SITE_LVL") = MID(Session("strMonthly_Site"),INSTR(Session("strMonthly_Site"),",")+ 1, 2)
Session("SITE_LVL_CODE") = LEFT(Session("strMonthly_Site"),INSTR(Session("strMonthly_Site"),",")-1)

SELECT CASE CINT(Session("SITE_LVL"))

CASE 1 'Site

strQuery = "SELECT SITE_MARKET.MARKET_CODE, SITE_MARKET.MARKET_TEXT, SITE_ZONE.ZONE_CODE, SITE_ZONE.ZONE_TEXT, SITE_AREA.AREA_CODE, SITE_AREA.AREA_TEXT, SITE.SITE_CODE, SITE.SITE_TEXT " & _
            "FROM SITE_REGION INNER JOIN SITE_MARKET ON SITE_REGION.REGION_CODE = SITE_MARKET.REGION_CODE INNER JOIN SITE INNER JOIN SITE_AREA ON SITE.AREA_CODE = SITE_AREA.AREA_CODE " & _
            "INNER JOIN SITE_ZONE ON SITE_AREA.ZONE_CODE = SITE_ZONE.ZONE_CODE ON SITE_MARKET.MARKET_CODE = SITE_ZONE.MARKET_CODE " & _ 
            "WHERE SITE.SITE_CODE = '" & Session("SITE_LVL_CODE") & "'"

Set rsGet_Market = Server.Createobject("ADODB.Recordset")
rsGet_Market.Open strQuery, objConn

Session("Market_Market_Code") = rsGet_Market("MARKET_CODE") & " - " & rsGet_Market("MARKET_TEXT")
Session("Market_Zone_Code") = rsGet_Market("ZONE_CODE") & " - " & rsGet_Market("ZONE_TEXT")
Session("Market_Area_Code") = rsGet_Market("AREA_CODE") & " - " & rsGet_Market("AREA_TEXT")
Session("Market_Site_Code") = rsGet_Market("SITE_CODE") & " - " & rsGet_Market("SITE_TEXT")
Session("MARKET_CODE") = rsGet_Market("MARKET_CODE")

Session("Market_Market_Code1") = rsGet_Market("MARKET_TEXT")
Session("Market_Zone_Code1") = rsGet_Market("ZONE_TEXT")
Session("Market_Area_Code1") = rsGet_Market("AREA_TEXT")
Session("Market_Site_Code1") = rsGet_Market("SITE_CODE") & " - " & rsGet_Market("SITE_TEXT")
Session("Table_Lvl_Label") = "Shop"

CASE 4 'Market

strQuery = "SELECT SITE_MARKET.MARKET_CODE, SITE_MARKET.MARKET_TEXT, SITE_ZONE.ZONE_CODE, SITE_ZONE.ZONE_TEXT, SITE_AREA.AREA_CODE, SITE_AREA.AREA_TEXT, SITE.SITE_CODE, SITE.SITE_TEXT " & _
            "FROM SITE_REGION INNER JOIN SITE_MARKET ON SITE_REGION.REGION_CODE = SITE_MARKET.REGION_CODE INNER JOIN SITE INNER JOIN SITE_AREA ON SITE.AREA_CODE = SITE_AREA.AREA_CODE " & _
            "INNER JOIN SITE_ZONE ON SITE_AREA.ZONE_CODE = SITE_ZONE.ZONE_CODE ON SITE_MARKET.MARKET_CODE = SITE_ZONE.MARKET_CODE " & _ 
            "WHERE SITE_MARKET.MARKET_CODE = '" & Session("SITE_LVL_CODE") & "'"

Set rsGet_Market = Server.Createobject("ADODB.Recordset")
rsGet_Market.Open strQuery, objConn

Session("Market_Market_Code") = rsGet_Market("MARKET_CODE") & " - " & rsGet_Market("MARKET_TEXT")
Session("Market_Zone_Code") = "N/A"
Session("Market_Area_Code") = "N/A"
Session("Market_Site_Code") = "N/A"
Session("MARKET_CODE") = rsGet_Market("MARKET_CODE")

Session("Market_Market_Code1") = rsGet_Market("MARKET_TEXT")
Session("Market_Zone_Code1") = "N/A"
Session("Market_Area_Code1") = "N/A"
Session("Market_Site_Code1") = "N/A"
Session("Table_Lvl_Label") = "Market"

END SELECT

rsGet_Market.close
objConn.Close
set rsGet_Market= Nothing
set objConn= Nothing
response.redirect "Footfall_Report.asp"
%>

跟踪 SQL 查询时,我可以执行相同的 SELECT 而没有任何可见问题。

有人知道为什么会失败吗?

Correction, line 71 is rsGet_Market.close

好的。让我们仔细看看您的代码。

您总是调用 rsGet_Market.close,但仅为情况 1 和情况 4 创建它。也许您的 CINT(Session("SITE_LVL")) 不等于 1 且不等于 4。

but that doesn't generate any data.

是的,但是您总是为不存在的对象调用方法(函数)(Set 根据您的情况为 rsGet_Market 创建它)。这就是为什么你有错误 Object required: ''

无需深入研究如何构建代码等,这是一个足够简单的修复。

SELECT CASE CINT(Session("SITE_LVL"))
CASE 1 'Site

    'Recordset instantiated here
    Set rsGet_Market = Server.Createobject("ADODB.Recordset")
    rsGet_Market.Open strQuery, objConn

    'Lots of fluff here removed to emphasize the point
    '...

    'Close Recordset inside the Case statement
    rsGet_Market.close

CASE 4 'Market

    'Recordset instantiated here
    Set rsGet_Market = Server.Createobject("ADODB.Recordset")
    rsGet_Market.Open strQuery, objConn

    'Lots of fluff here removed to emphasize the point
    '...

    'Close Recordset inside the Case statement
    rsGet_Market.close

END SELECT

'Don't close rsGet_Market here as it might not exist and cause an error.
objConn.Close

通过将 rsGet_Market.close 移动到 Case 语句中,只有当 rstGet_Market 对象中存在相应的 ADODB.Recordset 时才会调用它。

You can't Close a Recordset that never exists in the first place.


不过,我们可以通过将实例化移到 Case 语句之外以消除更多重复来改进这一点 (DRY Principle)

'Recordset instantiated here
Set rsGet_Market = Server.Createobject("ADODB.Recordset")

SELECT CASE CINT(Session("SITE_LVL"))
CASE 1 'Site

    'Recordset will be open if data is returned.
    rsGet_Market.Open strQuery, objConn

    'Lots of fluff here removed to emphasize the point
    '...

    'Close Recordset inside the Case statement
    rsGet_Market.close

CASE 4 'Market

    'Recordset will be open if data is returned.
    rsGet_Market.Open strQuery, objConn

    'Lots of fluff here removed to emphasize the point
    '...

    'Close Recordset inside the Case statement
    rsGet_Market.close

END SELECT

'Release Recordset object from memory
Set rsGet_Market = Nothing

'Don't close rsGet_Market here as it might not exist and cause an error.
objConn.Close