Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 where should I flush the conn & recordset obj?
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

ngaisteve1
Junior Member

Malaysia
241 Posts

Posted - 26 August 2003 :  23:25:53  Show Profile  Send ngaisteve1 an ICQ Message
what do you think of my code below? Is it fine for me to close the connection and recordset object this way or before response.redirect? Or after response.redirect, it will still close them?

if not rs.eof then
response.redirect "rate_add_form.asp"
else
response.redirect "rate_login.asp?errormesg=Invalid user id or password. Try again."
end if

conn.close
set conn = Nothing
rs.close
set rs = nothing

jfitz
Junior Member

USA
345 Posts

Posted - 26 August 2003 :  23:28:53  Show Profile
I don't know if it really matters, but I think I would close the record set first, and then close the connection. Theoretically, the recordset is using the connection, and after the connection disappears, you might have a problem closing the record set. Like I said, I don't really know if it makes a difference, but I would always code it that way - in some other environments it probably will make a big difference.

--Jördan
It's a wasted day if you don't spend at least part of it flying upside down.
Go to Top of Page

Hamlin
Advanced Member

United Kingdom
2386 Posts

Posted - 27 August 2003 :  03:23:51  Show Profile
I always put it before the redirect, I was under the impression that nothing under the redirect gets executed, as its been redirected to the new page
Go to Top of Page

OneWayMule
Dev. Team Member & Support Moderator

Austria
4969 Posts

Posted - 27 August 2003 :  04:15:11  Show Profile  Visit OneWayMule's Homepage  Send OneWayMule an ICQ Message
I would close at least the recordset, and closing the database connection would be recommended too. Change the code to:
if not rs.eof then
	rs.close
	set rs = nothing
        conn.close
        set conn = Nothing
	response.redirect "rate_add_form.asp"
else
	rs.close
	set rs = nothing
        conn.close
        set conn = Nothing
	response.redirect "rate_login.asp?errormesg=Invalid user id or password. Try again."
end if

quote:
I was under the impression that nothing under the redirect gets executed,

Yeah, that's the way it works!

My MODs:
Birthdays - Custom Policy - F.A.Q. Administration - Forum Rules - Guestbook
Links Manager - MyOwnGoogle - Profile Views - Search Log - WebSearch

Useful stuff:
Forum and MOD Installation - MOD Installation Guide - Snitz v3.4.05 Readme - Free ASP Hosts - Support Snitz

Edited by - OneWayMule on 27 August 2003 04:15:45
Go to Top of Page

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 27 August 2003 :  04:26:09  Show Profile  Visit D3mon's Homepage
Why not set the result to a varibale then close the RS and DB connectioin before the if?
blnResult = rs.eof
rs.close
set rs = nothing
conn.close
set conn = Nothing
if not blnResult then	
        response.redirect "rate_add_form.asp"
else
        response.redirect "rate_login.asp?errormesg=Invalid user id or password. Try again."
end if


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"

Edited by - D3mon on 27 August 2003 04:27:16
Go to Top of Page

ngaisteve1
Junior Member

Malaysia
241 Posts

Posted - 27 August 2003 :  04:37:57  Show Profile  Send ngaisteve1 an ICQ Message
ok. Thanks.
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 27 August 2003 :  22:31:03  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
Also it is good practice to close the database, but on the newer versions of IIS when a page is finished loading it will close all the database connections that the page uses.

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets
Go to Top of Page

Gremlin
General Help Moderator

New Zealand
7528 Posts

Posted - 28 August 2003 :  06:49:21  Show Profile  Visit Gremlin's Homepage
The connection should close after a timeout on all versions of IIS afaik, but yes its better to close it explicitly rather than rely on the OS doing it for you.

Kiwihosting.Net - The Forum Hosting Specialists
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.41 seconds. Powered By: Snitz Forums 2000 Version 3.4.07