Look at this code snippet. Notice anything odd about it?
<cfquery name="Art">
SELECT *
FROM art
ORDER BY ArtName
</cfquery>
Yep, the <CFQUERY> tag in the above snippet is missing the DATASOURCE attribute. And yet, this code works. Why? Take a look at this Application.cfc file:
<cfcomponent>
<cfset this.datasource="cfartgallery">
</cfcomponent>
In ColdFusion Centaur you can now specify an application wide default datasource by setting this.datasource in Application.cfc. The specified datasource becomes the default for all <CFQUERY>, <CFSTOREDPROC>, and other tags that expect a datasource to be specified. Of course, datasource can still be specified manually if needed, and a specified datasource will override the application default one.
This is one of those duh! enhancements that just makes sense. And, as I'll explain in an upcoming post, it also has another important purpose.
<cfquery name="read" dataSource="#application.datasource#">
SELECT
FROM
WHERE
</cfquery>
That's a nice little enhancement. Thanks for sharing!
--- Ben
Well, bye bye to our ubiquitous, old reliable #application.dsn# ;-)
I have been with CF since version 3. Man I could have used this ... last century!!!
And there is was, hiding there in plain site (just waiting to be added as a feature in version 9).
Better late than never. And again confirming exactly why CF is, bar none, the language with which I consistently remain my most productive in.
Thanks!!!
Best regards,
g
<cfset s = {server="127.0.0.1",username="mail",password="pass"}>
and then do
<cfmail to="some@where.com" from="admin@foo.com" subject="Your Email" attributeCollection="#s#">
<cfset this.datasource = "APPDSN">
Thanks for the useful info, I'm looking forward to using it once I get it to work.....
:)
tam, make sure you don't actually specify the datasource explicitly in your <cfquery> tags, remove the whole datasource="" attribute if you use this.datasource.
--- Ben