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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

application.cfc onSessionEnd isnt running my query

Status
Not open for further replies.

Pirellio

Programmer
Aug 25, 2008
18
US
Cant seem to get my query to run when the session times out.

When a person logs in I set their id to session.userid

Now when the session times out, I want to run this query

<cfquery datasource="#application.dsn#">
UPDATE Logger
SET therein = '0'
WHERE logerid = #session.userid#
</cfquery>

Here is my entire application file. Never have been to good at the application file

<cfcomponent>
<cfscript>
this.name = "afentry";
this.applicationTimeout = createTimeSpan(0,0,1,20);
this.clientmanagement= "yes";
this.loginstorage = "session" ;
this.sessionmanagement = "yes";
this.sessiontimeout = createTimeSpan(0,0,1,10);
this.setClientCookies = "yes";
this.setDomainCookies = "no";
this.scriptProtect = "all";
</cfscript>


<cffunction name="onApplicationStart" output="false">
//set your app vars for the application
<cfset application.dsn = "afentry" />
</cffunction>

<cffunction name="onSessionStart" output="false">
<cfscript>
session.started = now();
</cfscript>

</cffunction>

<cffunction name="onSessionEnd" output="false">
<cfargument name = "sessionScope" required=true/>
<cfargument name = "applicationScope" required=true/>


<cfquery datasource="#application.dsn#">
UPDATE Logger
SET therein = '0'
WHERE logerid = #session.userid#
</cfquery>

<cfset var sessionLength = TimeFormat(Now() - sessionScope.started, "H:mm:ss")>

<cflock name="AppLock" timeout="5" type="Exclusive">
<cfset arguments.applicationScope.sessions = arguments.applicationScope.sessions - 1>
</cflock>


<cflog file="#this.name#" type="Information"
text="Session #arguments.sessionScope.sessionid# ended. Length: #sessionLength# Active sessions: #arguments.applicationScope.sessions#">
</cffunction>






</cfcomponent>
 
I believe the OnSessionEnd code should not be using #application# and #session# directly. Instead try using

arguments.sessionScope AND
arguments.applicationScope

I would also suggested wrapping the code in a cftry/cfcatch and logging any errors to a file. Then review the logs to see if any errors occurred.


----------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top