Exercise - Putting data from the Healthy Gym database on the Web
A simple exercise to apply the lessons learned
Let us say that our HealthyGym owner opens a website and wants to put all his schemes and their prices on a web page. How would he accomplish this? Let us perform this simple exercise. At the end of this exercise, the schemes, descriptions, and cost may be viewed over the Internet through a sample web server hosted on your own system. Let us try this out step by step.
· First, let us generate a server side script in Microsoft's active server pages using MS Access. Copy the schemesforweb.html html file onto your system in the same directory as the healthygym database.
· Open the healthygym database. Go to queries by clicking on the queries tab under objects. Now, select the 'schemesforweb' query by clicking on it once. It should be highlighted. This query simply selects the name, description, and costs of all available enrollment plans.
Screen Shot 9b: Highlight schemesforweb query
· Now, go to File -> export. In the pop up window, select Microsoft active server pages next to 'save as type'. Hit save.
Screen Shot 9c: Export to Active Server Pages
· In the next pop up window, click on the browse button next to 'HTML template' and select the schemesforweb.html file that you had saved earlier. Enter 'healthygym' next to data source name and leave the username and password fields blank. Enter 'schemesforweb.asp' next to 'server URL'. Enter '2' next to 'session timeout min'. Hit the OK button. After this, a file called schemesforweb.asp should appear in the same directory as the HealthyGym database.
Screen Shot 9d: Set values in export dialogue
· Open this file using notepad. It looks like plain html, but you will see a lot of commands enclosed within '<%' and '%>'. These tell the server what to do. Also, you will get an error if you try to open this file using Internet Explorer.
Screen Shot 9e: The ASP file
· The next step is to install an application server if you do not have one installed already. IIS or Internet Information Server is the server we use as it comes with Windows XP. Earlier versions come with PWS or personal web server. This may be used as well with those versions of windows. To install the application server, go to the control panel on your system. Double click on 'add or remove programs'. Now, click once on the computer icon on the left hand side that says 'Add or Remove Windows components.' If there is no tick mark next to Internet Information Server, click on the box next to it and click on the next button. You will be asked to insert your Windows XP CD.
Screen Shot 9f: Install Windows Component - IIS
· Once you have installed IIS, your application server is ready for your software and web pages. Open the directory c:\Inetpub\wwwroot. If windows is installed on the D: drive of your computer, you will have to go to d:\Inetpub\wwwroot. Create a new folder called 'Healthygym' here. Copy schemesforweb.asp into this directory.
· Now, open up internet explorer and type in http://localhost/healthygym/schemesforweb.asp. Oops! you get a page cannot be displayed message with an asp error that goes something like: Cannot find dsn. We forgot to configure our ODBC data source. So, the application layer has no idea how to talk to the database and, thus, the error.
· Go to control panel. Double click on administrative tools. Now, double click on ODBC data sources. Move to the 'system dsn' tab by clicking on it. Next, click the 'add' button. Select 'Microsoft Access Driver' and click on 'finish'. In the next pop up window, enter 'healthygym' next to name and a short description next to description. Click on 'select' in the database box. Now, select the filename and directory that corresponds to healthygym.mdb. Make sure the healthy gym database is closed when you do this. Hit OK.
Screen Shot 9g: The System DSN tab
Screen Shot 9h: Select the ODBC Driver
Screen Shot 9i: Enter values for yuor Datasource
· Try the site http://localhost/healthygym/schemesforweb.asp once again. You should see the following.
Screen Shot 9j: The output of our script
You just wrote and published a server side script. Good work. This chapter should have given you an idea about all the pieces that need to be put together to publish information from a database on the web. In the next chapter, we will take a brief look at some other important database-related issues.