代码之家  ›  专栏  ›  技术社区  ›  Rob Sked

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

  •  0
  • Rob Sked  · 技术社区  · 9 年前

    我最近不得不将一个(继承的)旧的Classic ASP VBScript报告网站从windows server 2003迁移到windows server 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而没有任何可见的问题。

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

    2 回复  |  直到 9 年前
        1
  •  1
  •   user692942    9 年前

    不必讨论如何构造代码等,这是一个足够简单的修复方法。

    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语句中,只有当存在对应的 ADODB.Recordset rstGet_Market 对象

    无法关闭一开始就不存在的记录集。


    但是,我们可以通过将实例化移到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
    
        2
  •  1
  •   Zam    9 年前

    更正,第71行为rsGet_Market.close

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

    你在打电话 rsGet_Market.close 总是,但只为情况1和情况4创建它。可能您的CINT(会话(“SITE_LVL”)不等于1,也不等于4。

    但这不会产生任何数据。

    是的,但您总是为不存在的对象调用方法(函数)( Set 在您的案例中创建 rsGet_市场 ). 这就是你出错的原因 需要对象:“”