当我尝试在index.cfm中触发简单的select查询时,使用Application.cfc中定义的数据源会显示错误消息。任何人都可以帮助我正确的代码序列吗?
错误:
变量PRIMARYDATASOURCE未定义
的Application.cfc
<cfcomponent>
<!--- Set up the application. --->
<cfscript>
this.name = ""; // app name from old cfapplication tag
this.sessionManagement = "Yes";
this.loginstorage="session";
this.setClientCookies = "Yes";
this.primarydatasource = "diet";
application.PRIMARYDATASOURCE = "diet";
</cfscript>
<cfsetting requesttimeout="100000" />
<cffunction name="onApplicationStart">
....
<cfquery datasource="#application.PRIMARYDATASOURCE#" name="getCostDetails">
select * from maimun.adCostDetails ORDER BY ID DESC
</cfquery>
....
</cffunction>
</cfcomponent>
答案 0 :(得分:6)
将行application.PRIMARYDATASOURCE = "diet";
移至onApplicationStart
功能并删除行this.primarydatasource = "diet";
。完成。
放置在Application.cfc
正文中的代码根本不会按照您的想法执行。一旦应用程序初始化,您只能访问application
范围 - onApplicationStart
就是此事件。将其视为Web应用程序的构造函数。