Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    South East UK. 35 miles east of London, in sight of the River Thames.
    Posts
    300
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Closing Record Sets

    Hi All,

    This is a real novice question. As a general rule of good asp coding practice, should you always set a record set to 'nothing' after closing it?

    For example:

    RSRates.Close
    Set RSRates = Nothing

    Regards

    Gary

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    Texas
    Posts
    287
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, absolutely!

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    South East UK. 35 miles east of London, in sight of the River Thames.
    Posts
    300
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Hi Fractalvibes,

    Well!, that was a very definate and unambiguous reply. Just what I needed. I'll edit my scripts and give them a try.

    Thanks

    Gary

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you should also close your conection and set it to nothing, right after you closed the last open recordset.

    The most efficient method is
    - open connection
    - open recordset
    - dump recordset in a 2D array using the GetRows method on the recordsetobject
    - close recordset
    - close connection
    - and then used the array as your datasource to make your calculations or generate your poutput or whatever.

    (i vaguely remember i was going to rewrite a computationpage for you in this way...)

    Closing the connection and recordset and setting them to nothing, frees the resources that were allocated for these objects.
    Using the getrows will reduce your connectiontime (because your actual processing is done after disconnectiong), so you will have less simultanious (or concurrent) connections, which can lead to a huge performance gain, specialy if you use an MsAccess db or another 'almost single user' db.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #5
    Regular Coder
    Join Date
    Oct 2003
    Location
    London, UK
    Posts
    411
    Thanks
    0
    Thanked 1 Time in 1 Post
    Yes, open connections late, retrieve a minimal data set (i.e. no more rows or columns than you need) as quickly as possible (GetRows/GetString may or may not be suitable depending on the situation and if not, using disconnected recordsets is highly recommended where possible), close recordsets and connections as early as possible (use disconnected recordsets where advanced recordset functionality is required, but the data access is read-only), and dispose of the objects ASAP too.

    However, the last bit (disposal) is more of a established good practice rather than an absolute dictum (in many cases it's entirely unnecessary):
    http://blogs.msdn.com/ericlippert/ar...28/122259.aspx

    (Incidentally, Eric Lippert is Microsoft's top scripting dude, responsible for most of the VBScript/JScript engine code and much more, so he knows what he's talking about! )
    Marcus Tucker / www / blog
    Web Analyst Programmer / Voted SPF "ASP Guru"

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by M@rco
    However, the last bit (disposal) is more of a established good practice rather than an absolute dictum (in many cases it's entirely unnecessary):
    http://blogs.msdn.com/ericlippert/ar...28/122259.aspx
    reading all that was about the worst spent time this week.
    it basically says : my computer is so big, that i don't need to worry about efficient memory-management during scriptexecution. All resources will be cleared when the script finishes so why should i do it explicitly inside your code as soon as you no longer need them. Good thinking

    I gues low level programing with carefully thought out memorymanagement is gone out of fashion.
    Maybe this is part of the reason why you now need at least a PentiumII with a 2 Gig HD to be able to run your operation system, if it comes from the 'don't worry, the machine will work it out for you (later on)' guys from Redmont
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #7
    Regular Coder
    Join Date
    Oct 2003
    Location
    London, UK
    Posts
    411
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by raf
    reading all that was about the worst spent time this week.
    it basically says : my computer is so big, that i don't need to worry about efficient memory-management during scriptexecution. All resources will be cleared when the script finishes so why should i do it explicitly inside your code as soon as you no longer need them. Good thinking

    I gues low level programing with carefully thought out memorymanagement is gone out of fashion.

    Maybe this is part of the reason why you now need at least a PentiumII with a 2 Gig HD to be able to run your operation system, if it comes from the 'don't worry, the machine will work it out for you (later on)' guys from Redmont
    You obviously *did* waste your time, because you didn't understand what you read!!

    Yes, it is good thinking. Scripting languages are designed to be as flexible and easy-to-use as possible, and are designed accordingly.

    JScript and VBScript are late-bound, loosely-typed, interpreted languages, and a garbage collector is part of the scripting engines themselves.

    In contrast, operating systems are not written in script - for example, Windows is written in C++ which is early bound, explicitly typed, and compiled to machine code.

    Although it is arguably the case that modern versions of Windows are rather bloated and require large amounts of storage space (RAM + HD) and processing power, you must realise that the Windows experience that you enjoy now is far richer (and more importantly, far more stable) than it was back in the day when Windows 3.1 ruled the desktop. Add bundled drivers, media files, enhanced graphics, API cores, etc etc. and you get what we have today. I dislike software bloat as much as the next man, but Windows XP is definitely the best OS I have ever used (note that that's purely subjective - nothing can be all things to all men).

    Essentially it all boils down to power consumption - if you want to do more, you need more power and/or running costs are higher, just like air conditioning in a car.

    If all you want is a DOS console, run DOS!
    Marcus Tucker / www / blog
    Web Analyst Programmer / Voted SPF "ASP Guru"

  • #8
    Regular Coder
    Join Date
    Oct 2003
    Location
    London, UK
    Posts
    411
    Thanks
    0
    Thanked 1 Time in 1 Post
    Getting back to the point, generally speaking, it's supposed to be safe to the garbage collector handle cleanup automatically, but because of the use of objects like those which are part of ADO, and the Dictionary object, things get a little more complicated. Hence it probably remains best practice to clean up explicitly.
    Marcus Tucker / www / blog
    Web Analyst Programmer / Voted SPF "ASP Guru"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •