Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 503331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:22:59+00:00 2026-05-13T06:22:59+00:00

I have to use a Variable(Query Resultset) in ColdFusion , which will get the

  • 0

I have to use a Variable(Query Resultset) in ColdFusion, which will get the results from Other Application DB, and stores in Coldfusion Application.

The main idea is that I need to call the other Application DB only at Server startup time and cache the results in local. And I need to read the variable in other pages in my Application. I won’t overwrite that variable in any page.

On googling I found that ‘onApplicationStart‘ is useful to assign the variables at Application Startup time.

Is using the onApplicationStart fine or is there any other way? We can assign a variable at startup time(one time).

If onApplicationStart is fine: how to use? Maybe any link where it is explained clearly is helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:23:00+00:00Added an answer on May 13, 2026 at 6:23 am

    Well, it depends. How often will this query data be updated? If it really is unchanging, then onApplicationStart() is a fine place to put it. However, if it will change every so often, you can just tell Coldfusion to cache the query for a certain period of time, then you don’t need to mess with onApplicationStart(), but rather when you call the query it will return the cached result automatically (within your specified time period).

    Regardless, I would write a custom function to retrieve the data. Then it will be trivial to call it from onApplicationStart() or elsewhere.

    Startup.cfc: (Named whatever you like)

    <!--- Replace the datasource name with your db name --->
    <cffunction name="getStartupQuery" hint="Returns a query recordset for startup">
        <cfargument name="datasource" required="no" type="string" default="OtherAppDB">
        <!--- Init the query variable --->
        <cfset var result = queryNew("id")>
    
        <!-- Get the query dataset --->
        <cfquery name="result" datasource="#arguments.datasource#">
             YOUR QUERY HERE
        </cfquery>
    
        <cfreturn result>
    </cffunction>
    

    Application.cfc: (Just the important parts)

    <cffunction name="onApplicationStart">
        <!--- init the startup.cfc, then retrieve the data
        and save it to the application scope. Remember the component name must match
        your component above --->
        <cfset var startup = createObject("component", "startup")>
        <cfset application.varFromOtherDB = startup.getStartupQuery()>
        <cfreturn true>
    </cffunction>
    

    Now, you should be able to access this variable from any CFM or CFC in your application using:

    <cfset myNewVar = application.varFromOtherDB>
    or
    #application.varFromOtherDB#
    

    IF you use the onApplicationStart() method, I highly recommend implementing a method to reinit the application. For an example, see this other discussion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 423k
  • Answers 423k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to grab a reference to the instance's singleton… May 15, 2026 at 11:29 am
  • Editorial Team
    Editorial Team added an answer Supporting all HTTP methods: sed 's#.*\(\[[^]]*\]\).*"[A-Z]* \(.*\) HTTP/[0-9.]*" \(.*\)#\1 \2… May 15, 2026 at 11:29 am
  • Editorial Team
    Editorial Team added an answer pre-commit hook is the only way that I find to… May 15, 2026 at 11:29 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.