Connecting to a Microsoft Access Database via DSN

For the web server to access a database, you need to define an ODBC data source. A data source contains the information required to connect to a data provider, in this case, a Microsoft Access database. Earlier in this book you learned about three types of data sources: User DSN, File DSN, and System DSN. File DSNs offer the most flexibility for web work. Because the information required to connect to the data source is stored in a text file, file DSNs can be readily shared with other users and even easily moved to another web server if needed.

The following hands-on exercise will walk you through the steps required to set up a File DSN on your computer.

1. Open the Windows Control Panel. If you are using Windows XP or Windows 2000, double-click the Administrative Tools icon and double-click the Data Sources (ODBC) icon. In Windows NT, choose the ODBC icon. The ODBC Data Source Administrator window appears, as shown in Figure 28-10.

Figure 28-10: Use the ODBC Data Source Administrator window to set up the required connection to your database.

4. Launch Internet Explorer and type http://localhost/NorthDB/ Employees.asp in the address box of your browser. Press Enter to execute the Active Server Pages (.asp) file or click the Go button. The contents of the Employees table should appear in your browser as shown in Figure 28-18.

The Source command uses Windows Notepad to display a source file. Because the script commands contained in the ASP file are evaluated on the server before the browser receives the page, the resulting page in the browser is 100% pure HTML code. Notice that the browser does not display any of your ASP code.

Figure 28-18: After adjusting the connection setting in the Employees.asp file (see step 2 above), you can request the ASP page by typing its URL in the web browser's address

Figure 28-19: When you examine the source code of an ASP page (as instructed in step 5 of Hands-On 28-6), you will only see the HTML code. The scripting code is evaluated on the server and only the resulting HTML is passed to the browser!