Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Closing a recordset
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Closing a recordset

 Post Reply Post Reply Page  12>
Author
witje View Drop Down
Newbie
Newbie


Joined: 25 May 2004
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote witje Quote  Post ReplyReply Direct Link To This Post Topic: Closing a recordset
    Posted: 25 May 2004 at 9:14am

just a simple question, does a recordset needs to be closed eatch time it is used ?

for example
set rs = con.execute(blabla)
set rs = con.execute(blalbal)
rs.close

or should that be
set rs = con.execute(blabla)
rs.close
set rs = con.execute(blalbal)
rs.close

?

Back to Top
KCWebMonkey View Drop Down
Senior Member
Senior Member
Avatar
Go Chiefs!

Joined: 21 June 2002
Status: Offline
Points: 1319
Post Options Post Options   Thanks (0) Thanks(0)   Quote KCWebMonkey Quote  Post ReplyReply Direct Link To This Post Posted: 25 May 2004 at 1:31pm
set rs = con.execute(blabla)
rs.close
set rs = con.execute(blalbal)
rs.close
Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post Posted: 25 May 2004 at 1:38pm
A good rule of thumb is "If you Set it, Close it - as soon as possible.

Lead me not into temptation... I know the short cut, follow me.
Back to Top
Semikolon View Drop Down
Senior Member
Senior Member


Joined: 09 September 2003
Location: Norway
Status: Offline
Points: 1718
Post Options Post Options   Thanks (0) Thanks(0)   Quote Semikolon Quote  Post ReplyReply Direct Link To This Post Posted: 25 May 2004 at 1:47pm
if you Open, then Close
if you Set, then Set to Nothing

not all methods has Close options
Back to Top
witje View Drop Down
Newbie
Newbie


Joined: 25 May 2004
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote witje Quote  Post ReplyReply Direct Link To This Post Posted: 26 May 2004 at 3:52am

wierd.. i mean you dont close photoshop befor you open a new image now do you?

Anyway.. so i cant do i big cleanup at the bottom of the page like

  If isObject(Rs) Then
   If Rs.State = 1 Then Rs.Close
  End If
  If isObject(Rs_) Then
   If Rs_.State = 1 Then Rs.Close
  End If
  If isObject(Rs__) Then
   If Rs__.State = 1 Then Rs.Close
  End If

  Con.Close
  Set Con = Nothing



So will it be a smart idea to do somthing like this?

Sub oCon
  Set Con = Server.CreateObject("ADODB.Connection")
  Con.Open ConStr
 End Sub

 Sub oRs(Rs, SQL)
  If isObject(Rs) Then
   If Rs.State = 1 Then Rs.Close
  End If
  Set Rs = Con.Execute(SQL)
 End Sub

 Sub cCon
  If isObject(Rs) Then
   If Rs.State = 1 Then Rs.Close
   Set Rs = Nothing
  End If
  If isObject(Rs_) Then
   If Rs_.State = 1 Then Rs-.Close
   Set Rs_ = Nothing
  End If
  If isObject(Rs__) Then
   If Rs__.State = 1 Then Rs__.Close
   Set Rs__ = Nothing
  End If

  Con.Close
  Set Con = Nothing
 End Sub

Dim Rs
oCon()
oRs Rs, "select * from whatever"
  [..]
oRs Rs, "select * from somthingelse"

cCon()



It would be great if somthing like that is posible to use...

Back to Top
Semikolon View Drop Down
Senior Member
Senior Member


Joined: 09 September 2003
Location: Norway
Status: Offline
Points: 1718
Post Options Post Options   Thanks (0) Thanks(0)   Quote Semikolon Quote  Post ReplyReply Direct Link To This Post Posted: 26 May 2004 at 4:08am
of course you can place it in functions/subs, but you must ALWAYS close a recordset/connection/file/whatever before opening a new one with the same object
Back to Top
witje View Drop Down
Newbie
Newbie


Joined: 25 May 2004
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote witje Quote  Post ReplyReply Direct Link To This Post Posted: 26 May 2004 at 4:33am

ok thx, i think im going to create a class for this :)

One more question i forgot about earlier do i also have to set the Recordset object to nothing befor using it again?

 

Back to Top
Semikolon View Drop Down
Senior Member
Senior Member


Joined: 09 September 2003
Location: Norway
Status: Offline
Points: 1718
Post Options Post Options   Thanks (0) Thanks(0)   Quote Semikolon Quote  Post ReplyReply Direct Link To This Post Posted: 26 May 2004 at 6:35am
no.. you set it to Nothing before you do a redirect and at the end of the page.. or after you are finished with it.. the sooner the better
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.