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

Application.cfc can't get application.dsn = "Generic"; to work

Status
Not open for further replies.

wrighterb

Programmer
Feb 20, 2007
80
US
<cfcomponent>
<cfscript>
this.name = "Order";
this.applicationTimeout = createTimeSpan(0,4,0,0);
this.clientmanagement= "yes";
this.loginstorage = "session" ;
this.sessionmanagement = "yes";
this.sessiontimeout = createTimeSpan(0,4,0,0);
this.setClientCookies = "yes";
this.setDomainCookies = "no";
this.scriptProtect = "all";
</cfscript>

<cffunction name="onApplicationStart" output="false">
<cfscript>
//set your app vars for the application
application.dsn = "Generic";
application.sessions = 0;
APPLICATION.Vendor = StructNew();
APPLICATION.Vendor = CreateObject( "component", "componds.Vendor" );
</cfscript>

<cftry>
<!--- Test whether the DB is accessible by selecting some data. --->
<cfquery name="testDb" datasource="#application.dsn#" maxrows="2">
SELECT Count(*)
FROM theAccounts
</cfquery>
<!--- If we get a database error, report an error to the user, log the
error information, and do not start the application. --->
<cfcatch type="database">
<cflog file="#this.name#" type="error"
text="DB not available. message: #cfcatch.message# Detail: #cfcatch.detail# Native Error: #cfcatch.NativeErrorCode#" >
<!--- <cflocation addtoken="no" url="login.cfm" /> --->
<cfthrow message="This application encountered an error connecting to the database. Please contact support." />

<cfreturn false>
</cfcatch>
</cftry>

<cflog file="#this.name#" type="Information" text="Application #this.name# Started">

<cfreturn True>
</cffunction>

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


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

<cflock scope="application" timeout="5" type="Exclusive">
<cfset application.sessions = application.sessions + 1>
</cflock>
</cffunction>

<cffunction name="onSessionEnd" output="false">
<cfargument name = "sessionScope" required=true/>
<cfargument name = "applicationScope" required=true/>
<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>

<cffunction name="onRequestStart">
<cfargument name="requestname" required=true/>
<!--- Regular maintenance is done late at night. During those hours, tell
people to come back later, and do not process the request further. --->
<cfscript>
if ((Hour(now()) gt 2) and (Hour(now()) lt 4)) {
WriteOutput("The system is undergoing periodic maintenance.
Please return after 7:00 AM Eastern time.");
return false;
} else {
this.start=now();
return true;
}
</cfscript>

<!--- Check for login here --->
</cffunction>


<cffunction name="onError" output="true">
<cfargument name="exception" required=true/>
<cfargument name="eventName" type="String" required=true/>
<!--- Log all errors. --->


<!--- Display an error message if there is a page context. --->
<cfif (trim(arguments.eventName) IS NOT "onSessionEnd") AND (trim(arguments.eventName) IS NOT "onApplicationEnd")>
<cflog file="#this.name#" type="error"
text="Event name: #arguments.eventName#" >
<cflog file="#this.name#" type="error"
text="Message: #arguments.exception.message#">

<cfoutput>
<h2>An unexpected error occurred.</h2>
<p>Please provide the following information to technical support:</p>
<p>Error Event: #arguments.eventName#</p>
<p>Error details:</p>
</cfoutput>
<cfdump var=#arguments.exception#>
<cfelseif (arguments.eventName IS "onApplicationEnd")>
<cflog file="#this.name#" type="Information"
text="Application #this.name# Ended" >
</cfif>
</cffunction>

</cfcomponent>
 
It worked first, then I placed an order on my site

after the order is place

<CFSET STRUCTCLEAR(APPLICATION)>
<CFSET STRUCTCLEAR(SESSION)>
<CFLOOP INDEX="x" LIST="#GetClientVariablesList()#">
<CFSET DELETED = DELETECLIENTVARIABLE("#x#")>
</CFLOOP>
<CFCOOKIE NAME="cfid" EXPIRES="NOW">
<CFCOOKIE NAME="cftoken" EXPIRES="NOW">
<CFCOOKIE NAME="cfglobals" EXPIRES="NOW">

I do that and boom.... thats all she wrote application.cfc won't run again to restablish all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top