| Author |
Topic Search Topic Options
|
witje
Newbie
Joined: 25 May 2004
Status: Offline
Points: 6
|
Post Options
Thanks(0)
Quote Reply
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
?
|
 |
KCWebMonkey
Senior Member
Go Chiefs!
Joined: 21 June 2002
Status: Offline
Points: 1319
|
Post Options
Thanks(0)
Quote Reply
Posted: 25 May 2004 at 1:31pm |
|
set rs = con.execute(blabla) rs.close set rs = con.execute(blalbal) rs.close
|
 |
dpyers
Senior Member
Joined: 12 May 2003
Status: Offline
Points: 3937
|
Post Options
Thanks(0)
Quote Reply
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.
|
 |
Semikolon
Senior Member
Joined: 09 September 2003
Location: Norway
Status: Offline
Points: 1718
|
Post Options
Thanks(0)
Quote Reply
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
|
 |
witje
Newbie
Joined: 25 May 2004
Status: Offline
Points: 6
|
Post Options
Thanks(0)
Quote Reply
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...
|
 |
Semikolon
Senior Member
Joined: 09 September 2003
Location: Norway
Status: Offline
Points: 1718
|
Post Options
Thanks(0)
Quote Reply
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
|
 |
witje
Newbie
Joined: 25 May 2004
Status: Offline
Points: 6
|
Post Options
Thanks(0)
Quote Reply
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?
|
 |
Semikolon
Senior Member
Joined: 09 September 2003
Location: Norway
Status: Offline
Points: 1718
|
Post Options
Thanks(0)
Quote Reply
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
|
 |