Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: Session_OnEnd


Message #1 by "Angel Valdez" <gijoevaldez@y...> on Mon, 4 Mar 2002 21:42:48
My Session_OnEnd does not apear to be fireing correctcly. I am wanting to 

create and delete database records of login information, and right now 

they are being INSERTED ok but not deleteted when the session ends.



This is what I am currently using:



Sub Session_OnEnd

Dim MySession

MySession = cdbl(Session.SessionID)

	' Decrease the active visitors count when the session ends.

	Application.Lock

		Application("ActiveUsers") = Application("ActiveUsers") - 1

		Application("SessionEndedId")= Session.SessionID 

	Application.UnLock



	Set DelConn = Server.CreateObject("ADODB.Connection")

	DelConn.Open(MDB_Dsn_string)

	UserRec = "Delete * FROM qUserTable WHERE Session_Id = " & 

MySession

	

	DelConn.Execute(UserRec)

	' Close the database down again

	DelConn.Close

	Set DelConn = Nothing



End Sub
Message #2 by "Charles Mabbott" <aa8vs@m...> on Mon, 04 Mar 2002 18:59:14 -0500
Here is an example right out of book that seems to work well

for on start etc.  That I have been playing with on a web page,

it is saved as global.gsa in the root directory of the web page.

Regards,

Chuck



<SCRIPT LANGUAGE=VBScript RUNAT=Server>

Sub Application_OnStart

  Application("visits") = 0

  Application("Active") = 0

End Sub



Sub Application_OnEnd



End Sub



Sub Session_OnStart

  Session.Timeout = 1

  Session("Start") = Now

  Application.lock

    Application("visits") = Application("visits") + 1

    intTotal_visitors = Application("visits")

  Application.unlock

  Session("VisitorID") = intTotal_visitors



  Application.lock

    Application("Active") = Application("Active") + 1

  Application.unlock

End Sub



Sub Session_OnEnd

  Application.lock

    Application("Active") = Application("Active") - 1

  Application.unlock

End Sub

</SCRIPT>



***********  end of example **************



>From: "Angel Valdez" <gijoevaldez@y...>

>Reply-To: "Access ASP" <access_asp@p...>

>To: "Access ASP" <access_asp@p...>

>Subject: [access_asp] Session_OnEnd

>Date: Mon, 4 Mar 2002 21:42:48

>

>My Session_OnEnd does not apear to be fireing correctcly. I am wanting to

>create and delete database records of login information, and right now

>they are being INSERTED ok but not deleteted when the session ends.

>

>This is what I am currently using:

>

>Sub Session_OnEnd

>Dim MySession

>MySession = cdbl(Session.SessionID)

>	' Decrease the active visitors count when the session ends.

>	Application.Lock

>		Application("ActiveUsers") = Application("ActiveUsers") - 1

>		Application("SessionEndedId")= Session.SessionID

>	Application.UnLock

>

>	Set DelConn = Server.CreateObject("ADODB.Connection")

>	DelConn.Open(MDB_Dsn_string)

>	UserRec = "Delete * FROM qUserTable WHERE Session_Id = " &

>MySession

>

>	DelConn.Execute(UserRec)

>	' Close the database down again

>	DelConn.Close

>	Set DelConn = Nothing

>

>End Sub












"Racial interaction is described by Physics,

for every action there is an opposite

reaction.  We hate them, they hate us, and

we hate them back. And there you are, we are

trapped by mathematics."

    -Londo B5



http://aa8vs.dhs.org:81/aa8vs





_________________________________________________________________

Send and receive Hotmail on your mobile device: http://mobile.msn.com



Message #3 by "Angel Valdez" <gijoevaldez@y...> on Tue, 5 Mar 2002 17:20:54
I don't have a problem with subtracting or adding using variables. My 

problem is only with the Session_onEnd. It doesn't seem to fire when it 

should and process the code.





Message #4 by "Ken Schaefer" <ken@a...> on Thu, 7 Mar 2002 16:52:44 +1100
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From: "Angel Valdez" <gijoevaldez@y...>

Subject: [access_asp] Re: Session_OnEnd





: I don't have a problem with subtracting or adding using variables. My 

: problem is only with the Session_onEnd. It doesn't seem to fire when it 

: should and process the code.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



How are you causing Session_onEnd to fire?



Cheers

Ken



Message #5 by "Owain Williams" <email@o...> on Fri, 8 Mar 2002 11:11:36
A rather confusing error!



You could try periodiocaly writing to a log file to see if any errors 

occur. One thing to remember is that you can not use ther Server.MapPath 

method or the Response or Request objects. One other question, where is 

the 'MDB_Dsn_string' variable created and assigned?



Here is an example of how to write to a log file:



Sub WriteLog(strLog)



Const fsoForAppend = 8

Dim objFSO

Dim objTextStream



	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")



	'Open the text file

	Set objTextStream = objFSO.OpenTextFile("C:\LogFile.txt", _

		fsoForAppend)



	'White to the log file

	objTextStream.WriteLine strLog



	'Close the file and clean up

	objTextStream.Close

	Set objTextStream = Nothing

	Set objFSO = Nothing



End Sub



Sub Session_OnEnd



	On Error Resume Next

...

Your Code Here

...

	'Add this condition around the sections of code you want to check

	If Err.Number = 0 Then

		Set DelConn = Server.CreateObject("ADODB.Connection")

	Else

		WriteLog Err.Number & " " & Err.Description

	End If

...

Your Code Here

...

End Sub



Hope this helps.

  Return to Index