House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Cant find datasource in CFC

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Colman, Richard
04/10/2008 05:12 PM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Nathan Strutz
04/10/2008 05:25 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ian Skinner
04/10/2008 05:34 PM

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.


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

May 24, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
     1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31     

Designer, Developer and mobile workflow conference