Solved

Can I retrieve all recordsets from a collection?

Posted on 2002-06-14
11
256 Views
Last Modified: 2008-03-06
hi,

I wonder if it is possible to retrieve all recordsets by looping in a collection. A bit like:

For each rsTest in Recordsets
    ...
Next

I've tried the code above and this one:

for each rsTest  in cnMyConnection.recordsets
     ....
next

But it told me "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another."

What I want to do is a loop that get all my recordsets, close them and set them to nothing automatically.
(I'm maintaining a site where recordsets are not closed explicitly and typing them all will be a very big job!)

Thanks
0
Comment
Question by:FraggleRock
  • 6
  • 3
  • 2
11 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 7077715
if you add all the recordsets at creation into a collection, you can do that:

dim Recordsets 'as collection
set Recordsets = new collection
   
...
recordsets.Add rsData1
...
recordsets.Add rsData2

...


for each rsTest in Recordsets
  rs.Close
  set rs = nothing
next
'this is important !
set Recordsets = nothing


0
 
LVL 1

Author Comment

by:FraggleRock
ID: 7077725
Thanks very much!

That was quick!! :)

Christophe
0
 
LVL 9

Expert Comment

by:Nitin Sontakke
ID: 7077766
I will be glad if i am wrong, but give a thought to the following...

According to COM philosophy, as i understand it, the object is cleared from memory when ALL the references to that object are removed.

Now, see what is happening in above code. When you say Recordsets.Add rsData1 is not the 'reference' of rsData1 being copied in the collection?

When you call .close and set rs = nothing in a for next loop, is rsData1 still not hanging around?

Again, i might be wrong, but worth considering.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:FraggleRock
ID: 7077768
I have a problem with it.

I've just tried it and I have the following error message:
Error Type:
Microsoft VBScript runtime (0x800A01FA)
Class not defined: 'collection'
/scripts/billing/bllitemisemobile.asp, line 44


Is there something I've forgot?

I am using IIS5 with SQL Server 2000.

Thanks for your help

Christophe
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7077769
You are not wrong, and this is why is have this:
>>'this is important !
>>set Recordsets = nothing

Clearing the recordsets objects will clear also all the last reference to the recordset objects...

CHeers

0
 
LVL 9

Expert Comment

by:Nitin Sontakke
ID: 7077775
You cannot have strongly typed variables (such as string, integer, collection, etc.) in ASP.

You can use dictionary instead (Set recordsets = Server.CreateObject("Scripting.Dictionary")), but then you will have change your for next loop as well...
0
 
LVL 1

Author Comment

by:FraggleRock
ID: 7077779
I forgot to put the code:
dim Recordsets
set Recordsets =new collection

And the problems comes when I set the recordsets.

Thanks for your help
Christophe
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7077787
Sorry, forgot that you are in ASP:
set Recordsets = Server.CreateObject("VBA.Collection")

CHeers
0
 
LVL 1

Author Comment

by:FraggleRock
ID: 7077811
angelIII, your solution seems fine on paper but I have the following error with the VBA.Collection:

Server object, ASP 0177 (0x800401F3)
Invalid class string

The server is my local machine and I have Access installed so it should find the object.
Also, I am not sure that the VBA library is installed on our live server...

In the meantime, I'll give a go to the dictionnary option
0
 
LVL 1

Author Comment

by:FraggleRock
ID: 7077852
Well, I'm stuck both ways even if both solutions are good.
Unfortunately, I don't have much time as I am pressed to carry on with other work.

But thanks anyway for your help, I'll carry on looking into it when I'll have a bit of free time.

NitinSontakke, I'll set up a question for you to get 200 points as well, your contribution has been as valuable as angel's one.

Just give me 5 minutes.

Christophe
0
 
LVL 1

Author Comment

by:FraggleRock
ID: 7078059
NitinSontakke, please go to the following question to claim your points:
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=asp&qid=20311655

Thanks,
Christophe
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
asp syntax 3 66
RegEx Help - open to other simple suggestions 8 63
Microsoft SQL ADO Conn Issue 6 58
send email part1 9 39
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question