【问题标题】:How to resolve runtime error ('800a01a8' ) in VBScript (classic ASP)?如何解决 VBScript(经典 ASP)中的运行时错误('800a01a8')?
【发布时间】:2012-10-04 01:19:19
【问题描述】:

我有以下经典的 asp 代码:

     <BODY>

  <%   
 'In this example, we show how to connect FusionCharts to a database.
 'For the sake of ease, we've used an Access database which is present in
 '../DB/FactoryDB.mdb. It just contains two tables, which are linked to each
 'other. 

 'Database Objects - Initialization
 Dim oRs, oRs2, strQuery
 'strXML will be used to store the entire XML document generated
 Dim strXML

 'Create the recordset to retrieve data
  Set oRs = Server.CreateObject("ADODB.Recordset")

 'Generate the chart element
  strXML = "<graph caption='Factory Output report' subCaption='By Quantity'         decimalPrecision='0' showNames='1' numberSuffix=' Units' pieSliceDepth='30' formatNumberScale='0'>"

 'Iterate through each factory
strQuery = "select * from deal_price"
Set oRs = oConnection.Execute(strQuery)

While Not oRs.Eof
'Now create second recordset to get details for this factory
Set oRs2 = Server.CreateObject("ADODB.Recordset")
strQuery = "select sum(price) as TotOutput from deal_price where deal_id=" &  ors("deal_id")
Set oRs2 = oConnection.Execute(strQuery) 
'Generate <set name='..' value='..'/> 
strXML = strXML & "<set name='" & ors("name") & "' value='" & ors2("TotOutput") & "' />"
'Close recordset
Set oRs2 = Nothing
oRs.MoveNext
Wend
'Finally, close <chart> element
strXML = strXML & "</chart>"
Set oRs = nothing

'Create the chart - Pie 3D Chart with data from strXML
 Call renderChart("MyWeb/includes/FCF_Pie2D.swf", "", strXML, "FactorySum", 650, 450)
 %>
 </BODY>
  </HTML>

DB连接文件代码:

Dim oConnection
Set oConnection = Server.CreateObject("ADODB.Connection")
oConnection.Open "Provider=SQLOLEDB; Data Source=MA-PC\SQLEXPRESS; Initial      Catalog=test; User ID=missy; Password=hello;"

我在以下行中遇到运行时错误: 设置 oRs = oConnection.Execute(strQuery)

我似乎无法解决问题,我哪里出错了。任何助手将不胜感激。提前谢谢你。

【问题讨论】:

  • 您的 DBConn.asp 中是否定义了 oConnection?
  • 亲爱的@andrew,我检查了变量,但我仍然得到同样的错误..:(
  • 您正在打开然后关闭连接,然后将其设置为 Nothing。复制 oConnection.Close 并设置 oConnection = Nothing 并将其放在代码中的 Set oRs = oConnection.Execute(strQuery) 之后。

标签: graph asp-classic vbscript


【解决方案1】:

您收到错误的原因是您的包含文件 (DBConn.asp) 正在打开连接、关闭连接并将其设置为 Nothing。

从 DBConn.asp 文件中删除:

oConnection.Close
Set oConnection = Nothing

更改您的代码:

   'Create the recordset to retrieve data
        Set oRs = Server.CreateObject("ADODB.Recordset")

       'Generate the chart element
        strXML = "<graph caption='Factory Output report' subCaption='By Quantity'         decimalPrecision='0' showNames='1' numberSuffix=' Units' pieSliceDepth='30' formatNumberScale='0'>"

     'Iterate through each factory
      strQuery = "select * from deal_price"
      Set oRs = oConnection.Execute(strQuery)

      While Not oRs.Eof
      'Now create second recordset to get details for this factory
      Set oRs2 = Server.CreateObject("ADODB.Recordset")
      strQuery = "select sum(Quantity) as TotOutput from Factory_Output where FactoryId=" &  ors("FactoryId")
      Set oRs2 = oConnection.Execute(strQuery) 
      'Generate <set name='..' value='..'/> 
      strXML = strXML & "<set name='" & ors("FactoryName") & "' value='" & ors2("TotOutput") & "' />"
      'Close recordset
      Set oRs2 = Nothing
      oRs.MoveNext
    Wend
     'Finally, close <chart> element
      strXML = strXML & "</chart>"
      Set oRs = nothing

    'Create the chart - Pie 3D Chart with data from strXML
     Call renderChart("../../FusionCharts/FCF_Pie3D.swf", "", strXML, "FactorySum", 650, 450)
'Create the recordset to retrieve data
    Set oRs = Server.CreateObject("ADODB.Recordset")

   'Generate the chart element
    strXML = "<graph caption='Factory Output report' subCaption='By Quantity'         decimalPrecision='0' showNames='1' numberSuffix=' Units' pieSliceDepth='30' formatNumberScale='0'>"

 'Iterate through each factory
  strQuery = "select * from deal_price"
  Set oRs = oConnection.Execute(strQuery)

  While Not oRs.Eof
  'Now create second recordset to get details for this factory
  Set oRs2 = Server.CreateObject("ADODB.Recordset")
  strQuery = "select sum(Quantity) as TotOutput from Factory_Output where FactoryId=" &  ors("FactoryId")
  Set oRs2 = oConnection.Execute(strQuery) 
  'Generate <set name='..' value='..'/> 
  strXML = strXML & "<set name='" & ors("FactoryName") & "' value='" & ors2("TotOutput") & "' />"
  'Close recordset
  Set oRs2 = Nothing
  oRs.MoveNext
Wend
 'Finally, close <chart> element
  strXML = strXML & "</chart>"
  Set oRs = nothing

'Create the chart - Pie 3D Chart with data from strXML
 Call renderChart("../../FusionCharts/FCF_Pie3D.swf", "", strXML, "FactorySum", 650, 450)


'Add these lines back in as you are done processing your records
 oConnection.Close
 Set oConnection = Nothing

 %>

【讨论】:

  • 非常感谢您的帮助。我目前是经典 asp 的新手,所以我发现这些愚蠢的错误太慢了。感谢您的时间和帮助。
猜你喜欢
  • 2018-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多