korssane
10-22-2011, 04:07 AM
Hi guys,
i have build my application.cfc file and i am using the following to declare my dns under application start session :
<cfset application.dns="MyDNS">
now how can i call that #application.dns# as my data source in other cfm pages ?
thanks
Gjslick
10-22-2011, 06:14 PM
Exactly as you have it. You can put it in a <cfquery> as such:
<cfquery name="myQuery" datasource="#application.dsn#">
(query text)
</cfquery>
Be aware though that the onApplicationStart method only runs on the first request to an application. This means that if you have added that <cfset> after running some pages in your application, #application.dsn# will not be set until you do one of the following:
a) Restart the ColdFusion service on your computer.
b) Let the application time out (which you probably don't want to wait for!), or
c) If you have ColdFusion 9, you can run the applicationStop() function in a .cfm page, and the next request to a page will cause onApplicationStart() to execute, and set your variable.
-Greg
korssane
10-23-2011, 12:25 AM
thanks Gjslick,
do you think this is something needs to be called on RequestStart..
i am using only 2 dsn's in whole applications
thanks
Gjslick
10-23-2011, 04:58 PM
Hey korrsane,
No, this is something that belongs in onApplicationStart. The <cfset> for application.dsn should only have to execute once when the ColdFusion application starts, and not on every request to a .cfm page.
-Greg
seikialice88
11-15-2011, 02:57 AM
thanks Gjslick,
do you think this is something needs to be called on RequestStart..
i am using only 2 dsn's in whole applications
thanks
I also think so.
__________________
Watch The Twilight Saga: Breaking Dawn Online Free (http://fullmoviesonlinefree.net/)