Solved

Can I retrieve all recordsets from a collection?

Posted on 2002-06-14
11
252 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 142

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 6

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
 
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 142

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

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 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using AJAX to call classic ASP function 4 82
Syntax Help on SP 4 56
INNER JOIN ? 8 40
Classic ASP - problem with MS SQL Select Query? 10 57
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 …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
A short film showing how OnPage and Connectwise integration works.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now