SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    calling my dns from application.cfc

    Hi guys,

    i have build my application.cfc file and i am using the following to declare my dns under application start session :


    <cffunction name="On ApplicationStart">
    <cfset application.dns="MyDNS">
    ....
    ....



    now how can i call that #application.dns# as my data source in other cfm pages ?



    thank

  2. #2
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Aberdeen, Scotland
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't you mean dsn? Dns is domain name :-)

    Anyway to call it on a cfm page it should be just a case of using that reference you've put in onApplication. Ie

    <cfquery name="myQuery" datasource="#application.dsn#">
    Select ID from myDBTable
    </cfquery>

    or do you mean something else?

    By the way application variables are values persisted in memory throughout the life of the application. They don't relate to sessions which are used for each visitor to your application.

    Hope that helps

    Cheers
    James

  3. #3
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Clarkee21 ,

    i am trying to use that but it does not work

    <cfset DNS1="#application.dsn#">
    <cfquery name="myQuery" datasource="#DNS1#">
    Select ID from myDBTable
    </cfquery>

    it says DNS1 is undefined...


    what is the best way to define the dns ..is it as an application variable or session one..anyway my whole application uses 2 different dns's .

    any idea ?


    Thanks

  4. #4
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Aberdeen, Scotland
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DSN = Datasource Name.

    DNS means something completely different so it's best to get terminology right to avoid confusion.

    Have you defined a name for your application? It sounds like ColdFusion might be rebuild the application on every request.

    At the top of the Application.cfc place this:-

    <cfset this.applicationame = "myApplication" >

    There are a few more settings that you can define here but look those up on Adobe's online docs.

    You don't need the DNS1 = "#application.dsn#" either. All your doing here is duplicating variables. Just use application.dsn directly and it's less for you to manage / remember then :-)

    Cheers
    James

  5. #5
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ,

    Thanks a lot for the follow up and for the correction. You are right better using the right terminology..
    I am using dsn instead.... i think was just a typo ...
    I have build a new test page where i have to test that #application.dsn# and it is working just fine..


    thanks bro..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •