Server Time:
Monday May 12 2008 06:45 AM  
Your Time:
  
HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

DSNLess Coldfusion?
by: Pablo Varando
Email this tutorial to a friend Display Printer Friendly Format
[Download in PDF Format] [Download in FlashPaper Format]

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.


Date added: Fri. August 16, 2002
Posted by: Pablo Varando | Views: 23425 | Tested Platforms: CF5 | Difficulty: Intermediate
Categories Listed: Best Practices Databases

HostMySite.Com is sponsoring this tutorial, please visit their site today!
This tutorial is sponsored by HostMySite.Com - ColdFusion Hosting

This author's other tutorials:
Delete files and folders in a specified path!
This tutorial will demonstrate how you can delete all files and sub-folders in a specified folder using ColdFusion and Windows! - Date added: Wed. September 7, 2005
Dynamic Last Date Modified?
This tutorial will demonstrate how to display the date a web page was last modified to your visitors dynamically. - Date added: Mon. April 12, 2004
Correct Content (document) serving!
This tutorial will demonstrate how to correctly serve documents via ColdFusion and allow you to correctly name the download as you see fit! - Date added: Tue. February 10, 2004
Creating your very own RSS XML Feeds with ColdFusion MX!
Have you ever wanted to create your very own RSS XML News Feeds? This tutorial will show you how to create an RSS feed that will allow you to syndicate your web site and allow the world to easily use your data! - Date added: Thu. January 15, 2004
Processing XML/RSS feeds with ColdFusion MX
This tutorial will show you how to parse XML files (RSS Feeds) with ColdFusion MX and it uses an EasyCFM.COM Feed for example [Feed: 5 Most Viewed Tutorials]. It shows you how to call it via CFHTTP all the way to parse and display your records! - Date added: Sat. December 27, 2003

Additional Tutorials:
· Changing the form submission page on the fly!

· What is the ID for the record I just inserted?

· Creating a file content crawler with ColdFusion....

· Delete Records From Your Database With ColdFusion!

· Do you want to remember your members?

· Get A Folder Size Using ColdFusion and FSO...

· Preventing People From Leeching Your Images!

· Combining two queries into one..

· CaSe SensitiVe password logins!

· Creating an ODBC Connection within ColdFusion MX Server...

· Print your web pages on the fly!

· Using <CFPOP> and creating an email client for POP3 Email Reading!

· Using CFRegistry to Add Your IP To CF Debug IP List!

· Reading your IIS Log Files with ColdFusion!

· Automatically Adding Smiles To Your Messages!

· Using Arrays in ColdFusion To Properly Display Data....

· Implementing FORM Error Checking On Your Pages!

· Inserting FORM data into multiple database tables!

· Creating, Altering and Deleting database tables with ColdFusion.

· Sending multiple attachments with CFMAIL!

· ColdFusion and .INI Files!

· Clearing your session variables!

· Using PayPal's IPN with ColdFusion!

· Alternating Row Colors!

· Previous / Next n Records

· Using Query String Values....

· A quick intro into the world of Custom Tags!

· A brief demonstration of Fusebox 2.0

· Creating a Newsletter System....

· Count Active Users On Your Site.

· User Defined Functions....

· Creating a user athentication (Login) area.

· A Simple Contact Us Page….

· Having Your Database Do The Work… not ColdFusion!

· Retrieving Records From a Database..

· Inserting data into a database
Please rate this tutorial:
5 Stars 4 Stars 3 Stars 2 Stars 1 Stars
Comments on this tutorial
Read previous comments on this particular tutorial
SQL
how to do the same with SQL server
Posted by: Asim
Posted on: 06/16/2004 12:46 PM
Number of DSNs
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?
Posted by: tsuukai
Posted on: 07/09/2004 08:47 PM
need to have the full code
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..
Posted by: how to connect to ms sql databse from clodfusion
Posted on: 06/23/2005 05:16 AM
No More Connectionstring with Coldfusion
Macromedia coldfusion have stopped using this tag after CF 5. Bad or Good?
Posted by: Mayoorathen
Posted on: 07/01/2005 01:38 AM
something I found/read...
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.
Posted by: Charlie Seitz
Posted on: 05/08/2006 05:02 PM
database file
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

Posted by: Akos
Posted on: 02/06/2008 03:23 AM
Post a new comment on this tutorial
post a new comment on this particular tutorial
Your Name:
Your Email:
Comment Title:
Comments:
Key Phrase:
 
Skyscrapper Banner Advertisement
CF 8 Hosting for less then $40 a year!

You are 1 of 697 active sessions! | Privacy | Company
Copyright © 2002 EasyCFM.Com, LLC. (Easy ColdFusion Tutorials) All Rights Reserved
All other trademarks and copyrights are the property of their respective holders.
ColdFusion Hosting ColdFusion Hosting
ADD TO:
Blink
Del.icio.us
Digg
Furl
Google
Simpy
Spurl
Y! MyWeb