Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why session end but connection still there 2

Status
Not open for further replies.

hu68

Technical User
Feb 19, 2002
30
0
0
CA
Hi,all
There're a few asp page retriving data from database(Access),since all pages related with one database,I put database connection in session.As far as I know when user disconnect with the website,the everything in session will be destoried autometically.
but the strange thing is when I close the browser,the connection still there for about 15 minutes(bacause I check the database file ,the *.ldb file is there,it disappeard after 15 minutes,and I'm sure noone else use database during that time)
could some know the reason for it? any solution?
Thanks for any help !
 
Try explicitly deleting the connection object in your global.asa file in the Session_OnEnd section.
 
This might help,

When you're done with the database, add to your code:

rs.close
Set rs=nothing

Hope it'll help ;-) Have Fun...

Sharky99 >:):O>
 
Hi,Nagrom and Sharky99
Thanks for you reply, following your suggestion I put rs.close set rs=nothing in asp pages whenever database is done and put set session("conn")=nothing in session_onend in global.asa ,but these don't fix the problem,the *lb file still there for about 15 minutes after I close the browser .Any other thought?
Thanks!
 
Try Session.Abandon... Regards gsc1ugs
"Cant see wood for tree's...!"
 
Hi,gsc1ugs
I'm trying to use this method but I don't know where to put "session.abandon". Since I have no idea when the client finish their job ,I don't know which page is the last one.I can't put it in asp pages .Do you mean to put it in Glabol.asa session_onend?
 
Yeh... a new session should start there and end Regards gsc1ugs
"Cant see wood for tree's...!"
 
Hi,everyone
I put session.abandon in global.asa session_onend,but it doesn't help.any idea about it?
Any help will be greatly appreciated!
 
Hi,everyone
this is updated message
I did some test and found if I set the session.timeout=15
the database connection will destoried 15 minutes after I close the browser,IF I set timeout=1 the connection will destoried 1 minute after I close the browser.That means after I close the browser the session still alive.Could someone help find the reason for it?
 
May be some setting in your browser.. this is just a stab though. Regards gsc1ugs
"Cant see wood for tree's...!"
 
Best practice is to not set objects (in general) to have session scope. It tends to create problems, as you have uncovered here.

If you site gets any amount of traffic at all, then having x number of connections all open at the same time (in session) will cause your server to slow down severely and will cause slow response times on those connections (if not an out and out error)

Just take the connection completely out of session scope, and use them one by one on the pages where you need them, setting them = nothing when you're through with them, and your problems should disappear.

:)
paul
penny1.gif
penny1.gif
 
Ive got the same problem with to many connections on my mysql server but where hud64's timesout after 15 minutes or whatever other variable he sets, mine stays alive on my mysql server forever or until I shut it down and restart it. So after its been running for 2 minutes I get an error saying to many connections, is this a setting in mysql or asp ? BEcause in theory its somewhere in asp that it doesnt close the connection after its read the db.
 
Is there smart pointers or similar with asp cause they know when the db is free and close automatically Regards gsc1ugs
"Cant see wood for tree's...!"
 
Sory for sounding like a idiot but ive never heard of smart pointers I wrote the application in asp but dont have a global.asa file because I wanted to ad the setting int here to close the conection after a minute because that would help me allot if they did eventualy close because then I can just up the ammount of conections that my server handles. I use ado conections to get to my db server is ther a way of specifying a timeout in there?

Thanx for your quick response

Quinton
 
FYI Smart pointers C++ stuff Regards gsc1ugs
"Cant see wood for tree's...!"
 
Hi,everyone
Thanks for your reply. The discussion is interseting and helpful.
As Paul suggested "Best practice is to not set objects (in general) to have session scope....".but I'm not sure about the performance if we create a ADO connection,and then close it and set it =nothing in every page.is this expensive for resourse?
Thanks for everyone's attention.
 
No, it's not expensive (comparatively speaking). It's much less expensive to do it in this fashion, than the only other alternative, which is to store them with session scope, which is just plain bad.

I can't think of one possible instance where session connections might be a preferred method.

:)
paul
penny1.gif
penny1.gif
 
I have to disagree here. There is much less overhead to creating an object once at the session scope than to creating an object every time you hit a page if you use that object frequently. What you have to look at is the frequency of use of the object. If you are creating the connection with every page in your website then it is definitely better to create it at the Session scope. If, on the other hand, you are only using the connection on one page out of a multitude on the website, then yes, you would want to create it at the Page scope. It is a bad idea to make a blanket statement "You must do it like this" without first determining how the app is structured.
 
Define overhead. Is overhead the amount of work spent creating and destroying an object, or is overhead an overall measure of the amount of work your server is encountering in the span of a user's visit to your application/site? If your definition is of the first flavor, then yes I would agree with your disagreement, but if you have a more realistic view of what overhead in an application really consists of, then I would respectfully stand by my original statement and strongly suggest not placing com objects into session scope. Many developers (and for good reason) go so far as to say not to use session scope at all. Personally, I try to it as little as possible, but from time to time, I find it so useful, I just can't resist.

Some good reading:




and even MS advises not to do it

:)
paul
penny1.gif
penny1.gif
 
I know where you're coming from, and I am not saying I entirely disagree, but if you look at Microsoft's recommendations about (not using) the Session scope it's because they are not shared across web servers, so if you are using load balancing they should be avoided. That's another aspect to consider when developing your web application. What I'm saying is that you shouldn't just outright say, "Never use Session variables!" without first knowing more about the app structure and environment. It was definitely my bad not to mention about load balancing before, though - that is definitely a VERY important thing to consider.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top