ColdFusion Query attribute repetition

132 views Asked by At

I'm developing a basic ColdFusion application for a class and cannot control the CFAdmin. I was wondering if there was a way to avoid the repetition of the attributes datasource, username and password in each one of my queries, since they're always the same.

Replacing :

<cfquery name="name"
datasource="datasource"
username="username"
password="password">

By :

<cfquery name="name">

Thanks!

1

There are 1 answers

3
Avery Martell On BEST ANSWER

If you're using ColdFusion 9.01 or higher you can set these values within Application.cfc. In summary:

Application.cfc lets you specify data source authentication details for the data source. The data source settings can now be a string or a struct. When string, it is considered to be the data source name and authentication information is taken from the data source defined in the ColdFusion Administrator.

You can specify the authentication information using a struct value for data source. The following are the key names:

  • name: data source name
  • username: Username for the data source
  • password: Password for the data source

Example:

<cfset this.datasource={name='cfartgallery'
                           , username="user"
                           , password="passwd"}>

or

<cfset this.datasource="cfartgallery">