错误类型:ADODB.Recordset (0x800A0E79) 对象打开时不允许操作
Posted
技术标签:
【中文标题】错误类型:ADODB.Recordset (0x800A0E79) 对象打开时不允许操作【英文标题】:Error Type: ADODB.Recordset (0x800A0E79) Operation is not allowed when the object is open 【发布时间】:2012-07-16 14:05:40 【问题描述】:我正在处理这段代码,但它给了我一个错误,指出错误类型: 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"-->
谢谢 尼克
【问题讨论】:
我不能肯定地说,当你关闭 rows2 时,你会打开 rows3 我会说你有答案@Steve。 【参考方案1】:查看您的代码,我注意到在您的循环中您关闭了 Recordset rows2,但您忘记关闭 Recordset rows3。因此,在第一个循环之后的下一个循环中,当您尝试重新打开 rows3 记录集时会收到错误消息。 快速解决方法是:
....
rows2.close
rows3.Close
END IF
【讨论】:
以上是关于错误类型:ADODB.Recordset (0x800A0E79) 对象打开时不允许操作的主要内容,如果未能解决你的问题,请参考以下文章
无法将“ADODB.Recordset”类型的对象转换为“MSDATASRC.DataSource”类型
由于空格,ADODB.Recordset 到 SQL Server 查询失败