Should I place a DSN (datasource) definition inside or outside onApplicationStart() function?

115 Views Asked by At

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.

1

There are 1 best solutions below

0
James A Mohler On BEST ANSWER

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.