EasyCFM.COM ColdFusion Forums / Coding Help! / var datasource not recognised in cfc?

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: var datasource not recognised in cfc?

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts first

Shalinko
09-16-2013 @ 3:01 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 107
Joined: Sep 2007

Ok, so no takers on that....looking at this article
http://www.bennadel.com/blog/1642-Learning-ColdFusion-9-
Application-Specific-Data-Sources.htm I implemented it in
a test scenario and it works great. So now looking to
rewrite my Application.cfm as Application.cfc (long
overdue I suspect!)....but this will mean rewriting all
my queries without using #datasource#...!!:(
Can anyone say if I'm barking up the wrong cf'intree?

Shalinko
09-13-2013 @ 3:44 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 107
Joined: Sep 2007

Hi, I'm just starting to learn how to use cfc's.

I created an index page which calls the users.cfc which
is in a folder 'components':
<!---invoke users cfc--->
<cfinvoke component="components.users"
     method="retrieveUsers"
     returnvariable="allUsers">
</cfinvoke>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<InvalidTag http-equiv="Content-Type"
content="text/html;
charset=iso-8859-1" />
<title>CFC Test</title>
</head>

<body>
<table width="100%"  border="1" cellspacing="0"
cellpadding="3">
<tr>
   <td>First Name</td>
   <td>Last Name</td>
   <td>Email</td>
   <td>Status</td>
</tr>
<cfoutput query="getUsers">
<tr>
   <td>#fname#</td>
   <td>#fname#</td>
   <td>#email#</td>
   <td>#status#</td>
</tr>
</cfoutput>
</table>
</body>
</html>

users.cfc:
<cfcomponent displayname="Users" hint="ColdFusion
Component for Users">
<!--- This function retrieves all users from the
database --->
<cffunction name="retrieveUsers"
     hint="Gets all users from the database"
returntype="query">
   <cfquery name="getUsers" datasource="#datasource#">
      select * from dbo.stu_users
   </cfquery>
   <cfreturn getUsers>
</cffunction>
</cfcomponent>

This works fine if I hard code the datasource, but not
when i use #datasource#

but if I copy the query from the cfc and put it
directly in the index page and comment out call to cfc,
it works fine?

I have Application.cfm where the datasource is set
which works fine with rest of site at all folder
levels...so I really can't see why I get error
"variable datasource not defined" ONLY in that cfc?

Any help much appreciated...these cfc things look great
to use!



Website Designed and Developed by Pablo Varando.