Skip to main content
Inspiring
August 30, 2013
Question

Multiples DSNs' application.cfc

  • August 30, 2013
  • 1 reply
  • 556 views

Hi All,

Is it possible to set the multiple datasources on a Application.cfc using this.datasouce attribute?

CF 9, from application.cfc, you  can set

<cfset this datasouce ="myDSN1" > and no need to specify the DSN in the query.  My question is if I have multiples Datasouces, how can i set them up in application.cfc?

 

<

cfquery name="qDoctype">

select * from type

</cfquery>

Thanks

    This topic has been closed for replies.

    1 reply

    Carl Von Stetten
    Legend
    August 30, 2013

    You can't set up multiple datasources in Application.cfc to be used **implicitly** in your queries.  The "this.datasource" can only be set to one datasource name.  However, nothing is stopping you from storing a structure of datasource names in the application scope:

    <cfset application.myDSNs = StructNew()>

    <cfset application.myDSNs.DSN1 = "myDSN1">

    <cfset application.myDSNs.DSN2 = "myDSN2">

    ...

    Then in your query, you would do:

    <cfquery name="qDoctype" datasource="#application.myDSNs.DSN1#">

    ...

    HTH,

    -Carl V.