Submit Your Site For Free!

Email Address:
* URL:
*
*Indicates Mandatory Field

Terms & Conditions

DevWebProDK
FlashNewz
DevWebPro










Coldfusion: Finding The Bug

By Raymond Camden
Expert Author
Article Date: 2007-06-25

I was helping a user yesterday who ran into an odd problem.

His CFC was using Application.DSN (which is another problem) and he kept getting an error that said Application.DSN didn't exist.

He copied his line that defined Application.DSN and set it in the Request scope.

When he updated the CFC to use the Request scope, it worked fine. What was the problem? Here is some code that simulates his Application.cfm. See if you can spot it before reading on....

Application.cfm:
<cfset application.dsn = "goo">
<cfset request.dsn = "goo">
<cfapplication name="myapp">
<cfset application.random = "Paris Hilton is my idol....">

test.cfm:
<cfdump var="#application#">
<cfdump var="#request#">


If you run this test, you will clearly see that the Application scope only has one variable, random.

The Request scope shows the DSN. So now you can see what he saw - that the Application scope was working incorrectly and the Request scope worked fine.

But... look again. Do you see his CFAPPLICATION tag? It is after his application.dsn line. ColdFusion had not "started" the Application yet.

Therefore his DSN variable was actually added to the magical unnamed Application scope area. To see what I mean, simply add a dump before his CFAPPLICATION tag.

So two lessons from this:

1) First, always remember to put the CFAPPLICATION tag before any code that actually uses the Application scope.

2) Second, this is one more big reason to migrate to Application.cfc. If he had used onApplicationStart(), this would not/could not have happened.

Comments

About the Author:
Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com

Raymond Camden is Vice President of Technology for roundpeg, Inc. A long time ColdFusion user, Raymond has worked on numerous ColdFusion books and is the creator of many of the most popular ColdFusion community web sites. He is an Adobe Community Expert, user group manager, and the proud father of three little bundles of joy.



DevWebProDK is an iEntry, Inc. ® publication - All Rights Reserved Privacy Policy and Legal