Reputation: 3166
When is it appropriate to place DSN definitions inside the onApplicationStart() function vs outside of the function?
I have seen this method:
<cfset this.datasource = "datasource_name">
<cffunction name="onApplicationStart" returnType="boolean" output="false">
and I've seen it this way...
<cffunction name="onApplicationStart" returnType="boolean" output="false">
<cfset application.dsn = "datasource_name">
The only reasons I can find for this format is leaving the datasource outside the function is an older, still supported, but outdated way of doing things.
Is there any other reason for it?
I did find this question already, but it only states where DSNs should be declared, but not when to it should go inside vs outside.
Upvotes: 2
Views: 120
Reputation: 11120
Q: Should I place a DSN (datasource) definition inside or outside onApplicationStart()
function?
A: Outside
That way <cfquery>
, QueryExecute()
, and ORM can tap into that datasource information without that information being repeated.
Upvotes: 2