Go Back   CodingForums.com > :: Server side development > Other server side languages/ issues > ColdFusion

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-22-2011, 04:07 AM   PM User | #1
korssane
Regular Coder

 
Join Date: Jun 2011
Posts: 148
Thanks: 18
Thanked 0 Times in 0 Posts
korssane is an unknown quantity at this point
invoke application.dns

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

Last edited by korssane; 10-22-2011 at 04:19 AM..
korssane is offline   Reply With Quote
Old 10-22-2011, 06:14 PM   PM User | #2
Gjslick
Regular Coder

 
Join Date: Feb 2009
Location: NJ, USA
Posts: 476
Thanks: 2
Thanked 70 Times in 69 Posts
Gjslick will become famous soon enough
Exactly as you have it. You can put it in a <cfquery> as such:
Code:
<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
Gjslick is offline   Reply With Quote
Old 10-23-2011, 12:25 AM   PM User | #3
korssane
Regular Coder

 
Join Date: Jun 2011
Posts: 148
Thanks: 18
Thanked 0 Times in 0 Posts
korssane is an unknown quantity at this point
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
korssane is offline   Reply With Quote
Old 10-23-2011, 04:58 PM   PM User | #4
Gjslick
Regular Coder

 
Join Date: Feb 2009
Location: NJ, USA
Posts: 476
Thanks: 2
Thanked 70 Times in 69 Posts
Gjslick will become famous soon enough
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
Gjslick is offline   Reply With Quote
Old 11-15-2011, 02:57 AM   PM User | #5
seikialice88
New to the CF scene

 
Join Date: Nov 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
seikialice88 is an unknown quantity at this point
Quote:
Originally Posted by korssane View Post
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
seikialice88 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:07 AM.


Advertisement
Log in to turn off these ads.