Recordset.Close doesnt delete cursor

Hi!
I have a project in asp, using VBScript on the server side. I found out, that when I close a record set with RS.Close and delete the recordset then, the cursor that's been opened with RS.Open isn't deleted still.
As an example I made the following test:


ctr = 0
hlp = 0
On Error Resume Next
Err = 0
SQL = "SELECT * FROM Domain"
Set DB = Server.CreateObject("ADODB.Connection")
DB.Mode = adModeRead
DB.ConnectionString =
DB.Open "", ,
while Err = 0 and ctr < 1000
ctr = ctr + 1
hlp = hlp + 1
Set RS = Server.CreateObject("ADODB.recordset")
RS.Open SQL, DB
LogInfo "Attempt No. " & ctr, "ADO"
If hlp = 50 Then
hlp = 0
End If
RS.Close()
Set RS = Nothing
wend
DB.Close
Set DB = nothing

When I'm using oracle this loop runs into an error (talking about too many cursors) the moment I pass the maximum number of cursors (I tried it with 300 and with 500, the error occured in number 301 and in 501). When I'm using MS Access (97) I'll get the error with number 681 (telling me that I can't open any more recordsets).
The line with LogInfo only writes the text I give it into a log-file.

Has anyone an idea about this behavior?
TIA
Rudolf
[1311 byte] By [Rudolf] at [2007-11-17 13:05:55]
# 1 Re: Recordset.Close doesnt delete cursor
You're creating a new recordset object each time through the loop, which is not only slowing your application down but also probebly ausing problems in your database.

If you execute all of your queries using one connection, your database should be able to more effectively manage your queries than it was in your original code. In your original code, you were effectively creating a new connection to the database each time you created the recordset object.

I have modified your code a little - note that I have note tested this! The code now reuses a single recordset object and reuses the connection it establishes at the start of the listing.

ctr = 0
hlp = 0
On Error Resume Next
Err = 0
SQL = "SELECT * FROM Domain"
Set DB = Server.CreateObject("ADODB.Connection")
DB.Mode = adModeRead
DB.ConnectionString =
DB.Open "", ,
Set RS = Server.CreateObject("ADODB.recordset")
RS.ActiveConnection = DB

while Err = 0 and ctr < 1000
ctr = ctr + 1
hlp = hlp + 1
' remove: Set RS = Server.CreateObject("ADODB.recordset")
RS.Open SQL
LogInfo "Attempt No. " & ctr, "ADO"
If hlp = 50 Then
hlp = 0
End If
RS.Close()
'remove: Set RS = Nothing
wend
Set RS = Nothing
DB.Close
Set DB = nothing

When you close the Recordset, the cursor should also be deleted. You should also consider explicitly setting the location of the cursor to the application since you're not manipulating the data in the database.

Essam Ahmed
___________________________________________________
Author of JScript .NET Programming - Now Avaialble!
http://www.designs2solutions.com/jsnetprg

See how easy it is to:
o migrate from ASP to ASP .NET
o create a Web Service
o consume a Web Service from a Windows Forms app
o work with ADO .NET
o work with ADO in an ASP .NET application
o migrate from ADO to ADO .NET
o ...and more!

o Accepting subscriptions for a newsletter on the .NET Framework and JScript .NET - Subscribe Today!

http://www.designs2solutions.com/jsnetprg
eahmed at 2007-11-10 3:31:56 >
# 2 Re: Recordset.Close doesnt delete cursor
The code was part of a test that had the sole purpose to check a problem I have in my project and to demonstrate it. It's not a part of the code I actually want to use.
But Your tips work with this example, so thanks a lot.
Rudolf
Rudolf at 2007-11-10 3:32:56 >