|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Cant find datasource in CFC
I know the datasource is there, in the root directory. So why can't theColman, Richard 04/10/08 05:12 P Other than the obvious comment about how calling variables straight out ofNathan Strutz 04/10/08 05:25 P Colman, Richard wrote:Ian Skinner 04/10/08 05:34 P I know the datasource is there, in the root directory. So why can't the CFC find it ...?? Element DATASOURCE is undefined in APPLICATION. The error occurred in /var/www/html/coda/datatrack/DataTrack.cfc: line 14 12 : <cfargument name="getType" default="ALL" type="String" required="yes"> 13 : <cfargument name="id" default="0" type="Numeric" required="no"> 14 : <cfquery name="qTracks" datasource="#application.datasource#"> 15 : <cfif arguments.getType EQ "SINGLE"> 16 : exec usp_DataTrack_SELECT #arguments.id# Rick Colman Other than the obvious comment about how calling variables straight out of the application from within a CFC breaks your object encapsulation ( http://en.wikipedia.org/wiki/Separation_of_concerns) -- I would suggest dumping before your query. <cfdump var="#application#" /><cfabort /> if that doesn't solve it, move the dump/abort to the spot right before you called your cfc. Then to the top of the page, then to the previous file, if included, and up the chain, then to your application.cfm/cfc. On Thu, Apr 10, 2008 at 2:12 PM, Colman, Richard <colman@codagenomics.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- Colman, Richard wrote: > I know the datasource is there, in the root directory. So why can't the > CFC find it ...?? Most likely because the cfc is not in the root or a sub-directory under the root. If so then it is not being associated with any application.cfc|cfm file that may be in that root with their application name properties. Since the CFC does not have this application name property it does not belong to the application, or any application for that matter. Short term fix: Move the CFC so it is under the application directory OR add a matching <cfapplication name="..."...> tag to the CFC so that it belongs to the desired application construct. Long term fix: Don't have CFC's rely on external variable scopes. This is just one of many reasons why it is considered a best pratice to always pass all data to a component that it will need to use. Rather then having the CFC be aware of the application scope. Just pass the application variable to the CFC from the calling code and set it as an internal property of the CFC. Then it will work no matter where the CFC lives or how it is used, and it can easily be used by many different applications which would not be possible with the short term fix.
|
May 24, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||