“事务不能有多个具有此游标类型的记录集。”错误
我在我的经典 asp 应用程序中收到以下错误:
用于 ODBC 驱动程序的 Microsoft OLE DB 提供程序错误“80004005”
事务不能有多个具有此游标类型的记录集。 更改游标类型、提交事务或关闭其中一项 记录集。
我正在努力将代码从 Oracle 迁移到 SQL Server 2008,这是我在整个应用程序中不断看到的一个问题。
似乎找不到任何修复方法。
此代码块中的特殊情况:(我更改了选择以使其更短)
Set MyConn = Server.CreateObject("ADODB.Connection")
Call OpenORPSConnect(MyConn)
ql = "Select username from mytable"
set rs = MyConn.Execute(sql)
if not rs.EOF then username = rs(0)
if username = "" then username = theUser
rs.close()
set rs = nothing
MyConn.BeginTrans()
sql = "Select someReport from MyTable"
set rs = MyConn.Execute(sql)
do while not rs.EOF
TIMESTAMP = rs("TIMESTAMP")
rev = rs("REV")
select case whatChange
case "Target date"
sql = "Insert into " & caJustTable & _
" (TEXT, TIMESTAMP, CURRENTFLAG)" & _
" Values ( Text& "','" & COPY_TS & "', 'Y')""
MyConn.Execute(sql)
end select
sql = "update table, set this to that"
MyConn.Execute(sql) <-------- error happens here sometimes....
end if
rs.movenext
loop
rs.close()
set rs = nothing
I am getting the following error in my classic asp application:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
Transaction cannot have multiple recordsets with this cursor type.
Change the cursor type, commit the transaction, or close one of the
recordsets.
i am working on migrating the code from Oracle to SQL Server 2008, and this is an issue that i keep seeing here and there, all through out the application.
can't seem to find any fixes for it.
this particular case in this block of code: (i changed the selects to make them shorter)
Set MyConn = Server.CreateObject("ADODB.Connection")
Call OpenORPSConnect(MyConn)
ql = "Select username from mytable"
set rs = MyConn.Execute(sql)
if not rs.EOF then username = rs(0)
if username = "" then username = theUser
rs.close()
set rs = nothing
MyConn.BeginTrans()
sql = "Select someReport from MyTable"
set rs = MyConn.Execute(sql)
do while not rs.EOF
TIMESTAMP = rs("TIMESTAMP")
rev = rs("REV")
select case whatChange
case "Target date"
sql = "Insert into " & caJustTable & _
" (TEXT, TIMESTAMP, CURRENTFLAG)" & _
" Values ( Text& "','" & COPY_TS & "', 'Y')""
MyConn.Execute(sql)
end select
sql = "update table, set this to that"
MyConn.Execute(sql) <-------- error happens here sometimes....
end if
rs.movenext
loop
rs.close()
set rs = nothing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
既然在评论中回答了这个问题,我想把它变成一个更好的答案
你的问题似乎是
MyConn.BeginTrans()
没有MyConn.CommitTrans( )
或MyConn.RollbackTrans()
在您的选择案例中的 Insert 语句之后;因此,当您尝试更新数据时会引发错误。如果您在插入执行后提交或回滚,那么您的下一次执行应该可以正常工作。事实上,MyConn.BeginTrans() 位于简单的 select 语句之前,您可能会考虑将其移到 select 之后。我会做这样的事情(如果你想使用事务):
事务通常用于插入/更新或删除数据。既然您评论过,您不知道为什么 BeginTrans() 语句在那里,那么是的,您可以将其完全删除,但我建议您阅读事务并确保在稍后发生的插入和更新语句之后不需要它代码。
以下是 SQL 事务的参考:
http://www.firstsql.com/tutor5.htm
Since this was answered in the comments I wanted to turn it into a better answer
Your problem seems to be the
MyConn.BeginTrans()
has noMyConn.CommitTrans()
orMyConn.RollbackTrans()
after the Insert Statement in your select case; therefore, an error is thrown when you try to update the data. If you commit or Rollback after that insert execute then your next execute should work just fine. The fact that the MyConn.BeginTrans() is before a simple select statement you might consider moving it after the select.I would do something like this (if you want to use transactions):
Transactions are generally used for inserting/updating or deleting data. Since you commented you don't know why the BeginTrans() statement is there then yes you could remove it altogether but I would recommend reading up on transactions and making sure you don't need it after your insert and update statements which occur later in the code.
Here is a reference for SQL transactions:
http://www.firstsql.com/tutor5.htm
我认为 MyConn 最终可能需要关闭。这是你可以尝试的吗?
I think MyConn may need to be closed at the end. Is this something you can try??
您在连接上已经有一个打开的记录集,所以我认为问题是您的数据库不支持在同一连接上执行其他操作,直到记录集关闭为止。作为修复,我建议使用以下三个选项之一:
使用第二个连接(在其上运行事务)来运行更新表的 sql 语句。
在循环记录集时将所有语句收集到列表中,关闭记录集,然后运行语句(使用相同的连接)。
或者将数据拉入数据表并循环遍历该数据表而不是打开的记录集。
You already have an open recordset on the connection, so I think the problem is that your database does not support additional actions on the same connection until the recordset is closed. As a fix, I would recommend one of three options:
Use a second connection (on which you run the transaction) to run the sql statements that update the table.
Collect all statements into a list while you loop through the recordset, close the recordset, and then run the statements (using the same connection).
Or pull the data into a data table and loop through that rather than an open recordset.