Topic: var datasource not recognised in cfc?

Shalinko    -- 09-13-2013 @ 3:44 AM
  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"

<html xmlns="">
<InvalidTag http-equiv="Content-Type"
charset=iso-8859-1" />
<title>CFC Test</title>

<table width="100%"  border="1" cellspacing="0"
   <td>First Name</td>
   <td>Last Name</td>
<cfoutput query="getUsers">

<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"
   <cfquery name="getUsers" datasource="#datasource#">
      select * from dbo.stu_users
   <cfreturn getUsers>

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

Shalinko    -- 09-16-2013 @ 3:01 AM
  Ok, so no takers on that....looking at this article
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?

EasyCFM.COM ColdFusion Forums :