DSNLess Coldfusion?

ColdFusion 5.0 bring a new and existing feature known as DNS-Less connections.  In the ASP world it's been available for a while, so in the standards of making ColdFusion bigger and better then it's only understood that Macromedia would create a similar (yet, easier to use) way of doing things!

This new and exciting tool uses a new setting that must be in place in your <CFQUERY> tag. The best thing that you can do is to first set a variable called:

MyConnectionString

You can do this as follows:

<cfset MyConnectionString = "
                 Driver={Microsoft Access Driver (*.mdb)};
                 Dbq=
MyDatabase.mdb;
                 DefaultDir=
D:\path2files\;
                 Uid=Admin;
                 Pwd=Password;"
>

Note: there cannot be a space in the actual code, we had to place a space for formatting reasons!
Changing the This colored text to the name of your database file, then this colored text to the path on the server to your file, and finally the username and password if your database is password protected (this one is optional, if not leave as is!). I suggest that you specify this in your Application.cfm is you will need this throughout your website, otherwise leave it on the same page as the where the <cfquery> tag will call for it.

The next change needed is to alter the <cfquery> tag a little different than usual. there is a value that you always pass in <cfquery> that is titled datasource=""....  this will be absent as you are not really connecting to a datasource, but instead an actual direct database connection. Below you see a working example of the modified, faster working <cfquery> tag.

<cfquery name="GetExample" connectstring="#MyConnectionString#" dbtype="DYNAMIC">
Select        *
From          tablename
Order by    fieldname
</cfquery>

That's it, this is the best example I could possibly give you on how to use a dynamic <cfquery> connection.

All ColdFusion Tutorials By Author: Pablo Varando
Download the EasyCFM.COM Browser Toolbar!