Setting Up an ODBC Connection
In order for your applications, which you will be building soon, to know where the database file is and how to talk to it, you will use open database connectivity also known as ODBC. ODBC usually comes with several database drivers already installed such as Access, SQL Server, dBase, Excel, FoxPro, Oracle, and text. Each of these drivers knows the characteristics of their respective data type and communicates your SQL commands to it. This way you don't have to know exactly how to talk to each individual data type. This is the beauty of SQL!
Once you have a data file saved to an appropriate spot on your machine or on a shared drive on your network, you need to set up the ODBC connection. There are a couple of ways in which to do this.
Windows Control Panel
First open the control panel from your settings menu and choose the ODBC control panel. There are several tabs you can choose from but we will only be paying attention to the tab System DSN (Data Source Name).
FIGURE 16 ODBC Control PanelSystem DSN.
Now you need to locate the data file and establish an ODBC connection by clicking the Add button, which will bring you to a list of several types of database drivers to choose from. Select the Microsoft Access Driver. Once you have done this click Finish.
FIGURE 17 ODBC control panelselect the Microsoft Access driver.
Now you will tell the system the location of the Access database by clicking the Select button and locating the file. Next give the file a name. For our example we will name it shelleyCatalog. Don't use spaces for the name. You can use underscores (such as shelley_catalog) for the sake of clarity if needed. Now hit OK.
FIGURE 18 ODBC control panelnaming the ODBC connection and defining the location of the data source.
Now you have successfully set up your ODBC connection to the shelleyCatalog.mdb file which you will start working with later in this book.
FIGURE 19 ODBC control panelODBC connection is now set up.
ColdFusion Administrator
The better and far easier way to set up an ODBC connection is through the ColdFusion server's built-in administration screen. Again, if you are going through an ISP that is hosting your website, chances are you cannot use this. The ISP will have to set it up for you.
The ColdFusion server has a built-in administration interface that allows you to control many features of your server either locally or remotely. The server's URL is:
http://127.0.0.1/CFIDE/Administrator/index.cfm
You will be asked to enter a password to log into it. This is the password you entered when you originally set up the ColdFusion server.
FIGURE 110 ColdFusion server administrator.
Under the Data Sources heading select ODBC. This will list all the ODBC connections currently running on this machine. It tells you the name of the file and the ODBC driver it is using and verifies the connection. If you have made a change to a file and want to make sure the DSN connection is still intact, click the Verify link to have the application check it for you. Alternatively you can select the Verify All button at the top to have all of your DSNs verified.
Now you want to set up your ODBC connection (assuming you haven't already done so using the Windows ODBC control method). Once you select ODBC under the Data Sources heading you will see the list of your current ODBC connections. Select the ADD button with the appropriate database type selected in the drop-down menu. Here is where you will add the database name and the location of the database you will be using.
FIGURE 111 ColdFusion's ODBC administration screen.
Different database drivers ask for different types of information. All of them ask for three common pieces of information:
Database nameThis doesn't necessarily have to be the name of the database file but it is the name you will be using for that connection down the road.
DescriptionOnly used for reference. When you get to the point of running several types or different versions of a database this is a good way to remember which is which.
Database File or ServerUsing the Browse Server button you can locate the file on your hard drive or network. Using SQL server you must type in the location of the machine on your network. If this database file is on the same machine just type in (local) and enter the database name in the Database field next to Login Info.
NOTE
The Browse Server is a Java class application that under Netscape operates fine. However, under Internet Explorer (all versions) it may ask you to connect to the Microsoft site to download the necessary Java class files.
If you have set any password restrictions on a database be sure to enter that in this area. If you are using SQL server connections, select the CF Settings to enter this information.
After you have created the ODBC connection, go back to your list of ODBC connections and your new connection will be listed. You are now ready to start learning ColdFusion commands.
FIGURE 112 Verification that the ODBC connection was set up correctly.