>   First you have to put it into an application variable, so code similar 
to
 > this goes into the Application.cfm :
 >
 > <cflock>
 >   <cfif isDefined("Application.dsn")>
 >    <cfset application.dsn = "mydatasource">
 >   </cfif>
 > </cflock>
 >
 >
 >   Now you have to lock all your query statements every time you reference
 > the variable:
 >
 > <cflock>
 >   <cfquery datasource="#application.dsn#">
 >
 >    </cfquery>
 > </cflock>
 >
 >
 >    In this case, you have added additional locking code, which takes
 > additional processing time, with no real added benefit for storing the
 > datasource information in an application variable.


I disagree with that example. There is no reason to have to lock the entire 
query just to use the application variable. I think that's one of the most 
commonly used examples out there that are just not accurate. All you have to 
do is set a local variable at the top of your page to the application-scope 
datasource variable, and then reference the local variable name as the 
datasource in the cfquery tag:

<cflock timeout="5" throwontimeout="Yes" type="READONLY" 
scope="APPLICATION">
   <cfset variables.dsName = application.dsName>
</cflock>

And then in your query, use:

<cfquery name="getRecords" datasource="#variables.dsName#">
SELECT myColumn
FROM myTable
</cfquery>

There is no reason to have to wrap the entire query in your example, unless 
you're trying to prevent a race condition.


Regards,
Dave.


______________________________________________________________________
This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to