drago354
drago354

Reputation: 79

Coldfusion Application.cfc

This may be a stupid question, but when my datasource is in a cfm page it will work just fine, but when I put the datasource in my application.cfc it errors out.

Code from CFM file

<cfquery name = "getlist" datasource="jeb48_shoppingcart">
 SELECT ProductID, ProductName, ProductQty, ProductPrice, ProductDescription
 FROM Products;
</cfquery>

Code from CFC

<cfcomponent> 
   <cfset This.name = "TestApplication"> 
   <cfset This.clientStorage = "jeb48_northwind"> 
   <cfset This.clientmanagement="True"> 
   <cfset This.loginstorage="Session"> 
   <cfset This.sessionmanagement="True"> 
   <cfset This.sessiontimeout="#createtimespan(0,0,10,0)#"> 
   <cfset This.applicationtimeout="#createtimespan(5,0,0,0)#"> 
</cfcomponent>

Upvotes: 0

Views: 457

Answers (2)

osekmedia
osekmedia

Reputation: 683

One solution would be to define your datasource as an application variable witin your onapplication start. If you have multiple datasources you could use an application variable containing a structure of datasources. Antony is correct, you are only creating a reference to the datasource for client storage. This does not mean it works.

<cfset APPLICATION.dsn = {}>
<cfset APPLICATION.dsn.main = "jeb48_northwind">
<cfset APPLICATION.dsn.logging = "loggingDataSource">

<cfquery name = "getlist" datasource="#APPLICATION.dsn.main#">
SELECT ProductID, ProductName, ProductQty, ProductPrice, ProductDescription
FROM Products;
</cfquery>

Upvotes: 0

Antony
Antony

Reputation: 3781

Your Application.cfc is not setting the datasource correctly.

clientstorage is used by client variables - read more about that here

datasource is used for cfquery datasources:

<cfset this.datasource="cfartgallery">

You can read more about the datasource property here

Upvotes: 9

Related Questions