8 Replies Latest reply on Jan 13, 2014 10:42 PM by BKBK

    application.cfc saving old datasource?

    ctreeves

      I had a site on one server that I am moving to a new server.   I copied the files and database and created a new DSN.  I ran a simple query on a test page prior to moving the site, it was a one page site at that time.  I was able to connect to the database.

       

      Now I have a relatively simple application file.  I changed the name of the data souce in the file, but prior to that I made the mistake of opening a page on the site.  The old data souce is A, the new data source is B.  The application.cfc clearly (now) says B, but I get an error on every page saying it can't find A.  I did a search of the entire site and nowhere in any file does it list data source A.

       

      Here is the application file.

       

      <cfcomponent output="false">

       

        <!--- Name the application. --->

        <cfset this.name="SomeName">

        <!--- Turn on session management. --->

        <cfset this.sessionManagement=true>

       

        <cffunction name="onApplicationStart" output="false" returnType="void">

       

          <!--- Any variables set here can be used by all pages --->

          <cfset APPLICATION.DSN = "B">

       

                <!--- Define the mail server --->

                <cfset APPLICATION.MailServer = "MailServer">

                <cfset APPLICATION.AdminMail = "EMailAddress">

          <cfset APPLICATION.AdminMailPass = "PassWord">

         

        </cffunction>

       

      </cfcomponent>

       

      Any thought on what I've done wrong?

       

      Thank you!

        • 1. Re: application.cfc saving old datasource?
          ctreeves Level 1

          OK, it's kinda silly, but I changed the existing data source to what it was previously, and now it loads.  Why does this always happen as soon as you submit a question?

           

          Anyhow, why was the old data source "stuck"?

           

          Thanks again.

          • 2. Re: application.cfc saving old datasource?
            Aegis Kleais Level 3

            The data source needs to be defined outside the onApplicationStart() method, in an area known as the "pseudo-constructor".  Since application.cfc is called on every request, it reads the area outside the functions, and executes that code.  If you placed:

             

            <cfset this.datasource = 'default_datasource_name' />

             

            Then, that value is set on each page request.  If, instead, you define your variables inside the onApplicationStart() function, it is only executed once (when the application starts), and on subsequent page requests, the onApplicationStart() method is not called, so making a change there to the new value will not "take".

             

            You can manually call the onApplicationStart() method, which WILL re-execute that code, but it will not start a new application.

            • 3. Re: application.cfc saving old datasource?
              Aegis Kleais Level 3

              Oh, and your onApplicationStart() function should not be returning a void data type.  Instead, it should be set to return a boolean.  If that boolean value is set to false, the application will be instructed to not start, even when the method is fired off.

              • 4. Re: application.cfc saving old datasource?
                BKBK Adobe Community Professional & MVP

                ctreeves wrote:

                 

                ... The old data souce is A, the new data source is B.  The application.cfc clearly (now) says B, but I get an error on every page saying it can't find A.  I did a search of the entire site and nowhere in any file does it list data source A.

                The answer to the puzzle is as follows. The original application was still running in memory, with datasource A, even after you had modified the Application.cfc file. That is because the original application has not yet timed out, which means onApplicationEnd() has not yet been triggered.

                 

                The easiest way I know to reset an application is to change the application name. To do so in your case, change the line

                 

                <cfset this.name="SomeName">

                 

                to, for example,

                 

                <cfset this.name="SomeName2">.

                 

                Oh, and I hope you have saved the application file as Application.cfc, with capital A.

                • 5. Re: application.cfc saving old datasource?
                  ctreeves Level 1

                  I changed it to this:

                    <cffunction name="onApplicationStart" output="false" returntype="boolean">

                   

                  and got this error:

                   

                  The value returned from the onApplicationStart function is not of type boolean.

                  • 6. Re: application.cfc saving old datasource?
                    ctreeves Level 1

                    BKBK wrote:

                    Oh, and I hope you have saved the application file as Application.cfc, with capital A.

                     

                    Why is that, I'm on a Windows server, I thought they weren't case specific.  I changed it anyhow.

                    • 7. Re: application.cfc saving old datasource?
                      BKBK Adobe Community Professional & MVP

                      ctreeves wrote:

                       

                      I changed it to this:

                        <cffunction name="onApplicationStart" output="false" returntype="boolean">

                       

                      and got this error:

                       

                      The value returned from the onApplicationStart function is not of type boolean.

                       

                      Remember that you are currently returning void. Add the following at the end

                       

                      <cfreturn true>

                      • 8. Re: application.cfc saving old datasource?
                        BKBK Adobe Community Professional & MVP

                        ctreeves wrote:

                         

                        BKBK wrote:

                         

                        Oh, and I hope you have saved the application file as Application.cfc, with capital A.

                         

                         

                        Why is that, I'm on a Windows server, I thought they weren't case specific.  I changed it anyhow.

                         

                        You are right. Case-sensitivity is only relevant in UNIX systems. However, in my opinion, using a capital A is a tradition worth abiding by. After all, you wouldn't want your applications to fail when ported to UNIX systems.