Is that still an issue with the introduction of MX?  I thought it no longer was. 
 
We do a practice similar to that but we are using a system left over from the CF 4 days.  So what we do is something like this and this is off the top of head so may contain errors
 
Application.cfm:
<cflock scope="application" type="exclusive">
<cfset App = Duplicate(Application) />
</cflock>
 
<cfparam name="App.Build" default="" />
<cfset Build = "12-Mar-2006" />
 
<cfif App.Build NEQ Variables.Build>
<cfset App.DataSource = "whatever" />
bunch of other globally used settings
</cfif>
<cflock scope="application" type="exclusive">
<cfset Application = Duplicate(App) />
</cflock>
 
However for CFCs, typically we just have something like Variables.DataSource up at the top of it and our Init method sets it to whatever was fed.  Then all other methods can not run unless it has been initialized and that is enforced through a RaiseInit() call in each.

 
On 3/22/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
That's actually not good practice.  If you use the Application scope in the query, you're "supposed" to lock the scope around the query.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of Lyons, Larry
Sent: Wednesday, March 22, 2006 1:48 PM
To: '[email protected]'
Subject: RE: [CFCDev] Storing DSN parameters in a "global" variable


Cody ,

I typically set the DSN and similar params in a "global" variable. However,
one thing to consider when storing DSN parameters is do these parameters
change all that often? If not then why place these variables in the request
scope? By setting these params in the Request scope you set it and reset it
for each and every page request. It would seem to me that the application
scope is more appropriate for parameters that rarely, if ever change.

Here's how I handle these params, using your example:

<cfif not structKeyExists(application,"DSNParams")>
      <cflock name="appParamsLock" throwontimeout="yes" timeout="60"
type="exclusive">
           <cfset application.DSNParams = structNew()>
           <cfset application.DSNParams.DSP = "myDBPassword">
           <cfset application.DSNParams.DSN = "myDSN">
           <cfset application.DSNParams.DST = "ODBC">
      </cflock>
</cfif>

Then later on in deepest darkest Code land:

<cfquery name="foobar"
        datasource="#application.DSNParams.DSN#"
        username="#application.DSNParams.DSU#"
        password="#application.DSNParams.DSP"
        type="#application.DSNParams.DST#">
       select Dunno
     from   whoCares
     where  apathy = "true"
</cfquery>

hth,

larry

--
Larry C. Lyons
Web Analyst
BEI Resources
American Type Culture Collection
email: llyons(at)atcc(dot)org
tel: 703.365.2700.2678
--

> -----Original Message-----
> From: Cody Caughlan [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, March 22, 2006 12:53 PM
> To: [email protected]
> Subject: [CFCDev] Storing DSN parameters in a "global" variable
>
>
> Is there anything inherently wrong with storing your DSN
> parameters in a Request-scoped structure and referring to
> these in your cfquerys, e.g.:
>
> <!--- pseudo-code --->
> App.cfc::onRequestStart() {
>       Request.DSU = "myDBUser";
>       Request.DSP = "myDBPassword";
>       Request.DSN = "myDSN";
>       Request.DST = "ODBC";
> }
>
> .... later, in some code deep in your app...
>
> <cfquery name="foobar" datasource="#Request.DSN#"
> username="#Request.DSU#" password="#Request.DSP" type="#Request.DST#">
>       ....
> </cfquery>
>
>
> Apart from the encapsulation this *does not* give you, is
> there anything wrong with this? That is, your code is now
> tied to the Request scope. I
> *know* it would be much better to pass every DSN struct into
> your CFC that needs it (possibly using some kind of a
> centralized object factory like ColdSpring). I have a fellow
> developer who prefers this "global" approach. I say its bad,
> he says its OK, because Macromedia (now Adobe) will never
> take away the the REQUEST structure, so its not like the code
> will ever break. My argument is that its not "proper coding",
> his argument is the magnitude of convenience this affords.
>
> Whats the right answer?
>
> Thanks
> /Cody
>
>
>
>
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email
> to [email protected] with the words 'unsubscribe cfcdev' as
> the subject of the email.
>
> CFCDev is run by CFCZone (www.cfczone.org ) and supported by
> CFXHosting (www.cfxhosting.com).
>
> An archive of the CFCDev list is available at
> www.mail-archive.com/[email protected]
>
>


This electronic communication, together with any attachments, may contain
information that is legally privileged, confidential or otherwise private.
The information is intended only for the use of the individual or entity to
which it is addressed. If you are not the intended recipient, please be
aware that any disclosure, copying, distribution or use of the contents of
this communication or any attachment is strictly prohibited. If you have
received this communication in error, please immediately notify the original
sender and delete the received information from your system. Thank you.



----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at www.mail-archive.com/[email protected]




----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting ( www.cfxhosting.com).

An archive of the CFCDev list is available at www.mail-archive.com/[email protected]





--
Aaron Rouse
http://www.happyhacker.com/ ----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at www.mail-archive.com/[email protected]

Reply via email to