1

We know that when we closed the browser, session gets destroy.

Please help me with below query.

Lets say i have clicked on submit button on my registration page and internally it get called SQL store procedure, which takes more time to execute..

on same time if i closed the browse what will happen?

  1. Does my sql connection still available ? if yes then after closing browser still my store procedure is in execute mode?

  2. when exactly the session get destroy?

Would like to know more about this life cycle , Thanks

kiran
  • 190
  • 1
  • 1
  • 13

1 Answers1

2

First have this in mind.

  1. The session is connected with a cookie on the users browser.
  2. The session have a time out.

If anything of this two gone, the session is gone, so let see them analytically.

Cookie

If the cookie is a session cookie (temporary), then is gone when the user close the browser, if its not temporary then is gone when it expires, or of course if the user clears it, or if the user is in private mode is not even saved.

So when the cookie that is connected with the session is gone, you lose the session

The session can be lost even if the browser is not been able to read the session cookie for other reasons.

Session Data on server

The session that is connected with the cookie, is a Dictionary of data that lives on server. The session have a timeout, so if the user did not update the call to the server inside this time, the server kills the session data on server.

Also, note that the session can be served on the SQL Server, or in a service that runs on background and keeps that data in memory.

If you save the session data on the memory, then they can be lost even before the session times out, from IIS recycle, from the service itself that clears it for their reasons.

Server Side Time Out

If you call a long time function, and the users ends their connection, then the procedure will be continue to runs until either ends either gets a time out. This is not so safe if your process takes 10 minute to execute, you probably gets timeout and never ends correct, even if the user is still connected. If you talk for few seconds, then its relative ok, the procedure will executed even if the users close his browser side.

Check the time out of the page and the time out of the sql server side. If you end well with the user connected, you will end the same and if the user close their connection in the middle.

Have in mind that in a heavy multi user call situation you may have a problem from the session locks, read this q/a ASP.NET Server does not process pages asynchronously

So take care the procedure to not take more than few seconds.

Last words

The most "secure way" to not lost your session in a time period is to use well setup cookie, that is not temporary and keep their life for some months (google keeps their cookie for two years), and use SQL Server to saves your session data.

More details to read at:
ASP.NET State Management Recommendations
Session would not retain values and always return null
Keeping a related ASP.NET application's session alive from another ASP.NET application
ASP.NET Session State Overview

Community
  • 1
  • 1
Aristos
  • 66,005
  • 16
  • 114
  • 150
  • thanks for comment, i agree it's always safe not to take much time for executing sp. i have just asked you for details. ok so in short ans will be "YES" is that correct? – kiran Aug 24 '14 at 19:13