User Guide

24 Chapter 3 Querying a Database
Adding data source notes and considerations
When adding data sources to ColdFusion Server, keep these guidelines in mind:
Data source names should be all one word and begin with a letter.
Data source names can contain only letters, numbers, and the underscore.
Data source names should not contain special characters.
Although data source names are not case-sensitive, you should use a consistent
capitalization scheme.
A data source must exist in the ColdFusion Administrator before you use it on an
application page to retrieve data (unless you specify the data source
dynamically).
Specifying data sources dynamically
To specify a data source dynamically, use the following attribute in the cfquery tag:
dbtype = "dynamic"
Specify all the required ODBC connection information, including the ODBC driver
and the database location, in the
connectstring attribute. For example, you could
use the following code for a query that dynamically specifies the pubs database on a
local Microsoft SQLServer:
<cfquery name = "datelist"
dbtype = "dynamic"
blockfactor = 100
connectstring = "DRIVER={SQLSERVER};SERVER=(local);UID=sa;PWD=;
DATABASE=pubs">
SELECT * FROM authors
</cfquery>
The following example uses a Microsoft Access database:
<cfquery name="titles"
dbtype = "dynamic"
ConnectString="DRIVER=Microsoft Access Driver (*.mdb);
DBQ=C:\CFusion\Database\cfsnippets.mdb;DriverId=281;
FIL=MS Access;MaxBufferSize=2048;PageTimeout=5">
SELECT * FROM Courses
</cfquery>