Coldfusion Application Variable

s_hausen
s_hausen used Ask the Experts™
on
Hi,
I have an Application.cfc and I've defined some variables on it. but when i try to access the datasource on otherpage, i get error:

Element DATASOURCE is undefined in THIS.

here's the application.cfc code:
<cfcomponent>
<cfscript>
    this.Name = "CFML";
    this.ClientManagement = "false";
    this.datasource = "cfartgallery";
    this.SessionManagement = "true";
    this.SessionTimeout = "#CreateTimeSpan(0,0,30,0)#";
    this.loginStorage = "Session";
</cfscript>
</cfcomponent>

Open in new window


and the page index.cfm i'm trying to run the query has code:

<cfquery name="qGetArt" datasource="#this.datasource#">
SELECT ARTID, ARTNAME, "DESCRIPTION", PRICE
FROM ART
ORDER BY ARTNAME ASC 
</cfquery>

<cfdump var="#qGetArt#" label="Arts List" />

Open in new window


one more thing, how come i can access the datasource for my files which are located inside in a folder named: users.

any help, suggestion, comments and feedback would be deeply appreciated.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

That is not how you create an application scoped variable, you would do it like this...


in the onApplicationStart function ...

 <cfset application.datasource = "cfartgallery">

Then throughout your application, you can refer to it like this...

 #application.datasource#


Author

Commented:
thanks

Author

Commented:
i was wondering how can i access the #application.datasource# in my users folder. i created another Application.cfc  in it but the file inside users folder doesn't access it and gets the same error i was recieving earlier.

Element DATASOURCE is undefined in APPLICATION.
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Are you saying you have two application.cfc files ?   You only need one, to be placed in the root.

If you must have two, please let me know why...

Author

Commented:
no i just have one, but it looks like its working for all the files including the sub folders. thanks again for all your help.

You may have to refresh your application.  The onApplicationStart function only fires on application timeout which is usually set to a long time.  You can get around this by changing the application name, or setting the timeout temporarily to a short time limit.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial