【问题标题】:Coldfusion Application.cfcColdfusion 应用程序.cfc
【发布时间】:2014-10-21 23:04:47
【问题描述】:

这可能是一个愚蠢的问题,但是当我的数据源在 cfm 页面中时它会正常工作,但是当我将数据源放入我的 application.cfc 时它会出错。

来自 CFM 文件的代码

<cfquery name = "getlist" datasource="jeb48_shoppingcart">
 SELECT ProductID, ProductName, ProductQty, ProductPrice, ProductDescription
 FROM Products;
</cfquery>

来自 CFC 的代码

<cfcomponent> 
   <cfset This.name = "TestApplication"> 
   <cfset This.clientStorage = "jeb48_northwind"> 
   <cfset This.clientmanagement="True"> 
   <cfset This.loginstorage="Session"> 
   <cfset This.sessionmanagement="True"> 
   <cfset This.sessiontimeout="#createtimespan(0,0,10,0)#"> 
   <cfset This.applicationtimeout="#createtimespan(5,0,0,0)#"> 
</cfcomponent>

【问题讨论】:

  • 下次,“errors out”很模糊。如果您遇到错误,请附上实际错误消息。
  • 您在设置clientStorage之前是否尝试过更改顺序和设置clientmanagement?还要确保为客户端变量配置了数据库,请参阅:help.adobe.com/livedocs/coldfusion/8/htmldocs/… 确保按照上面链接中的说明设置 CDATA 和 CGLOBAL 表。

标签: coldfusion application.cfc


【解决方案1】:

您的 Application.cfc 未正确设置数据源。

clientstorageclient 变量使用 - read more about that here

datasource 用于 cfquery 数据源:

&lt;cfset this.datasource="cfartgallery"&gt;

您可以阅读有关datasource 属性here 的更多信息

【讨论】:

    【解决方案2】:

    一种解决方案是将您的数据源定义为在您的 onapplication 启动时的应用程序变量。如果您有多个数据源,则可以使用包含数据源结构的应用程序变量。 Antony 是正确的,您只是为客户端存储创建对数据源的引用。这并不意味着它有效。

    <cfset APPLICATION.dsn = {}>
    <cfset APPLICATION.dsn.main = "jeb48_northwind">
    <cfset APPLICATION.dsn.logging = "loggingDataSource">
    
    <cfquery name = "getlist" datasource="#APPLICATION.dsn.main#">
    SELECT ProductID, ProductName, ProductQty, ProductPrice, ProductDescription
    FROM Products;
    </cfquery>
    

    【讨论】:

    • 我想我误解了这个问题。 :)
    • 这也是我理解的问题的解决方案。 Application.cfc 中的“this”范围不会被复制到“application”范围。
    • datasource 不需要进入application 范围。定义数据源意味着您可以完全省略cfquery 中的数据源属性,例如&lt;cfquery name="getlist"&gt;。更多详情bennadel.com/blog/…
    • 不需要使用Application范围来处理这个问题,使用this.datasource就可以了。
    猜你喜欢
    • 1970-01-01
    • 2010-12-13
    • 1970-01-01
    • 1970-01-01
    • 2010-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多