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.

About This Tutorial
Author: Pablo Varando
Skill Level: Intermediate 
 
 
 
Platforms Tested: CF5
Total Views: 58,508
Submission Date: August 16, 2002
Last Update Date: June 05, 2009
All Tutorials By This Autor: 47
Discuss This Tutorial
  • HI there, is it possible to use the MyConnectionString DefaultDir=D:\path2files\; so it would connect to a .mdb file somewhere on the internet remotely like http://www.somesite.com/data ? Basically is there a way that Cf could connect to any .mdb file anywhere on any server? PLease help..Many thanks AKos

  • After reading this article I thought I was all set. But I am developing my applications in ColdFusion MX 7 and encountered the error below: "The tag does not have an attribute called connectstring. The valid attribute(s) are name, datasource, dbtype, sql, username, password, maxrows, blockfactor, timeout, dbname, cachedafter, cachedwithin, result, debug." Much to my dismay, I found that Macromedia added "connectionless" DSN's in CF 5, then took them away again in CFMX. Further researching this, I found out that this is because ColdFusion MX 7 no longer interfaces directly through ODBC. Instead it uses JDBC as the data access layer. I have yet to find a work around, So I will continue to setup my DSN references via the ColdFusion Administrator Interface.

  • Macromedia coldfusion have stopped using this tag after CF 5. Bad or Good?

  • hi, i would like to connect to ms sql server database using coldfusion program. i could connect database without any problem don't know hoow to retreieve records from my table created in ms sql.. i would appreciate if you could provide me with all possible coding... thanks in advance..

  • If I were to get a host that only allowed a certain number of DSNs, would using this code mean that I could use as many as I wanted to?

  • how to do the same with SQL server

Advertisement

Sponsored By...
Powered By...