错误类型:ADODB.Recordset(0x800A0E79)对象打开时不允许操作

时间:2012-07-16 14:05:41

标签: mysql excel ms-access asp-classic

我正在处理这段代码,但它给出了一个错误,说明错误类型: ADODB.Recordset(0x800A0E79) 对象打开时不允许操作。我以前从未遇到过这个错误。我想要做的是在特定文件夹中掺入新文件时更新访问文件。我正在用excel做同样的事情,这是完美的工作,当我添加访问部分,它给了我错误。这是我的代码,如果我能得到一些帮助就很好。

<!--#include file="header.inc"-->
<%

file = Request.querystring("file")

file = "C:\Reports\" & file

log("UPDATE UTILITY RUN---------" & file)

'Initialize Connection to report

Const adOpenStatic = 3

Const adLockOptimistic = 3

Const adCmdText = &H0001

Set objConnection = CreateObject("ADODB.Connection")

Set rows = CreateObject("ADODB.Recordset")

objConnection.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _

    "Data Source=" & file & ";" & _

        "Extended Properties=" &  Chr(34) & "Excel 12.0 Xml;HDR=No;IMEX=1" & Chr(34) & ";"  


'Initlialize Connection to Data

Set objConnection2 = CreateObject("ADODB.Connection")

Set rows2 = CreateObject("ADODB.Recordset")

objConnection2.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _

    "Data Source=" & Server.MapPath("data.xlsx") & ";" & _

        "Extended Properties=" &  Chr(34) & "Excel 12.0 Xml;HDR=Yes;IMEX=0" & Chr(34) & ";"  


'initialize Connection3 to Data

Set objConnection3 = CreateObject("ADODB.Connection")

Set rows3 = CreateObject("ADODB.Recordset")

objConnection3.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & 
Server.MapPath("tracker_dev_nik.accdb") & ";Persist Security Info=False;"       


'Query the spreadsheet

rows.Open "Select * FROM [WC-Stages$]", _

    objConnection, adOpenStatic, adLockOptimistic, adCmdText



'Print off the row's data

DIM JUR

DIM WC

DIM WC_NAME

DIM PRIORITY

DIM REP

DIM DELIVER

DIM ACCEPT

DIM REJECT

DIM REDELIVER

DIM STATUS

DIM SDATE

DIM DATA_STATUS

DIM DATA_STATUS_2

DIM DATA_SDATE

DIM DATA_SDATE_2

Do Until rows.EOF

    JUR = rows.Fields("F3").Value

    WC = rows.Fields("F4").Value

    WC_NAME = rows.Fields("F5").Value

    PRIORITY = rows.Fields("F7").Value

    REP = rows.Fields("F23").Value

    DELIVER = rows.Fields("F22").Value

    ACCEPT = rows.Fields("F24").Value

    REJECT = rows.Fields("F25").Value

    REDELIVER = rows.Fields("F26").Value

    STATUS = ""

    SDATE = ""

    DATA_STATUS = ""

    DATA_SDATE = ""

    IF NOT ( JUR = "" OR JUR = "Jur" ) THEN 'Ignore invalid rows (first two and 

last three)

        If IsNull(DELIVER) THEN

            STATUS = "undelivered"

            SDATE = "1/1/2000"

        ELSE

            IF IsNull(ACCEPT) THEN

                IF IsNull(REJECT) THEN

                    STATUS = "delivered"

                    SDATE = DELIVER

                ELSE

                    IF IsNull(REDELIVER) THEN

                        STATUS = "rejected"

                        SDATE = REJECT

                    ELSE

                        STATUS = "redelivered"

                        SDATE = REDELIVER

                    END IF

                END IF

            ELSE

                STATUS = "accepted"

                SDATE = ACCEPT

            END IF

        END IF



        query = "SELECT * FROM [Sheet1$] WHERE JUR = '" & JUR & "' AND WC = " & WC

        rows2.Open query, _

            objConnection2, adOpenStatic, adLockOptimistic, adCmdText



        'For access database connection

        query = "SELECT * FROM [Sheet1] WHERE JUR = '" & JUR & "' AND WC = " & WC

        rows3.Open query, _

            objConnection3, adOpenStatic, adLockOptimistic, adCmdText



        ' DATA_STATUS = rows2.Fields("Status").Value

        ' DATA_SDATE = rows2.Fields("SDate").Value


        DATA_STATUS = rows3.Fields("Status").Value

        DATA_SDATE= rows3.Fields("SDate").Value









        if dateafter( SDATE, DATA_SDATE ) AND STATUS <> DATA_STATUS then

            'Need to update the data with the new value

            log("UPDATE: " & jur & ":" & wc & "has been changed to " & STATUS)

            query = "UPDATE [Sheet1] SET [STATUS] = '" & STATUS & "', [SDATE] = 

'" & SDATE & "' WHERE [JUR] = '" & JUR & "' AND [WC] = " & WC


            response.write(query)


            objConnection3.execute(query)

        END IF  

        rows2.close
    END IF
    rows.MoveNext
Loop


log("UPDATE COMPLETE")      
        %>

<!--#include file="footer.inc"-->

由于 NIK

1 个答案:

答案 0 :(得分:1)

查看你的代码,我注意到在你的循环中你关闭了Recordset rows2,但你忘了关闭Recordset rows3。因此,在第一个循环之后的下一个循环中,当您尝试重新打开rows3 Recordset时,会收到错误消息。
快速解决方法是:

    ....
    rows2.close 
    rows3.Close
END IF