• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

application.cfc saving old datasource?

Explorer ,
Jan 09, 2014 Jan 09, 2014

Copy link to clipboard

Copied

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!

Views

1.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 09, 2014 Jan 09, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 09, 2014 Jan 09, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 09, 2014 Jan 09, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 13, 2014 Jan 13, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 13, 2014 Jan 13, 2014

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 10, 2014 Jan 10, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 13, 2014 Jan 13, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 13, 2014 Jan 13, 2014

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation