this.datasource - how to pass dsn, username and password to cfc?
I am currently converting/upgrading a CF9.0.2 application (Windows 2008R2/IIS 7, SQL Server 2008R2) environment to an internal company Share Hosting Environment that is CF11. My CF9 environment is very basic; it began in 2000 in CF 4.5 and new development was done in the newest version that was available - so nothing has been rewritten to the latest version.
Our SHE sets up the DATASOURCE for us - but we need to set the datasource, username and password into a passwords.cfm module in a restricted directory and therefore pass those parameters to each and every query. I cannot put this information an application.cfm or application.cfc.
I now have to bring my CF9 code to the SHE requirements, and one of the first I need to tackle is updating my CFGRIDS to HTML. I know the arguments of CFGRID - I don't need to be lectured about them please. All of the grids have sorts and 90% are selectmode=row (I have spent to much time trying to convert them to regular tables).
I have embedded the CFGRID into a CFFORM:
<cfform>
<cfgrid format="html" name="paymentcodegrid" pagesize=10 sort=true
bind="cfc:payment.getData({cfgridpage},{cfgridpagesize},
{cfgridsortcolumn},{cfgridsortdirection})">
<cfgridcolumn name="Payment_Type" header="Payment Code" width="95" />
<cfgridcolumn name="Payment_Desc" header="Payment Description" width="200" />
</cfgrid>
</cfform>
I have created a payment.cfc:
<cfcomponent>
<cffunction name="getData" access="remote" output="false">
<cfargument name="page">
<cfargument name="pageSize">
<cfargument name="gridsortcolumn">
<cfargument name="gridsortdirection">
<cfquery name="payment_all" datasource ="#this.name#" username ="#this.username#" password ="#this.password#">
SELECT payment_type, Payment_Desc FROM paytype
<cfif gridsortcolumn neq "" or gridsortdirection neq "">
order by #gridsortcolumn# #gridsortdirection#
</cfif>
</cfquery>
<cfreturn QueryConvertForGrid(payment_all, page, pageSize)>
</cffunction>
</cfcomponent>
I have create a CachedQuery.cfc to pull the DataSources information:
<cfcomponent
<cffunction name="init" access="public" returntype="CachedQuery" output="no">
<cfargument name="datasources" type="string" required="yes">
<cfset variables.datasources = arguments.datasources>
<cfreturn this>
</cffunction>
</cfcomponent>
In my login.cfm, I have the following:
<cfset Application.CachedQuery = CreateObject("component","CachedQuery").init(datasource=request.name)>
<cfset Application.CachedQuery = CreateObject("component","CachedQuery").init(datasource=request.username)>
<cfset Application.CachedQuery = CreateObject("component","CachedQuery").init(datasource=request.password)>
When I execute the page to open up the grid, I receive an error that states 'Element NAME is undefined in THIS'. I took a class on CFC years ago - but I didn't need to pass the dsn name at that time - so this is just killing me! I have been trying different combinations of things for the last 5 days, that I am besides myself! I am sure it is something quite simple - can anyone assist?
Libby H
