application.cfc 显示数据源消息 "Variable PRIMARYDATASOURCE is undefined" 的问题
Issue with application.cfc showing message "Variable PRIMARYDATASOURCE is undefined" for datasource
当我尝试使用 Application.cfc 中定义的数据源在 index.cfm 中触发简单的 select 查询时,它显示一条错误消息。任何人都可以帮助我正确的代码序列吗?
错误:
Variable PRIMARYDATASOURCE is undefined
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>
将行 application.PRIMARYDATASOURCE = "diet";
移动到 onApplicationStart
函数并删除行 this.primarydatasource = "diet";
。完成。
放置在Application.cfc
正文中的代码根本没有按照您认为的方式执行。您只能在应用程序初始化后访问 application
作用域 - onApplicationStart
是该事件的事件。将其视为 Web 应用程序的构造函数。
当我尝试使用 Application.cfc 中定义的数据源在 index.cfm 中触发简单的 select 查询时,它显示一条错误消息。任何人都可以帮助我正确的代码序列吗?
错误:
Variable PRIMARYDATASOURCE is undefined
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>
将行 application.PRIMARYDATASOURCE = "diet";
移动到 onApplicationStart
函数并删除行 this.primarydatasource = "diet";
。完成。
放置在Application.cfc
正文中的代码根本没有按照您认为的方式执行。您只能在应用程序初始化后访问 application
作用域 - onApplicationStart
是该事件的事件。将其视为 Web 应用程序的构造函数。