Connecting to a database via ASP

The ASP Connection

The next time you create a website think about how you want to get information to others. Is it information that is going to change or stay the same? If it's going to stay the same then you create your html document and you're done with it. However, if you want to change that information at a later date you have to update the document each time you have new information to add. Depending on how often you update this task can become a time consuming choir. There's a better way out there to serve up fresh web pages daily or even by the minute. We are going to explore the benefits of ASP (Active Server Page) technology and how to use it to connect to a database via your web page.

Getting Your ASP On

Example of an ASP tag

<% Response. Write "I'm an ASP Tag!" %>

ASP or Active Server Pages is a technology created by Microsoft back in the mid 90's. In non-technical terms it allows the web page to talk to the database and return results back to the web page via the server. ASP effectively allows you to create dynamic web pages rather than boring static pages.

The first thing you need to do is create an Access or SQL database to hold your information. I typically use Access first to design my tables that store the data. It's wise to map out your database design before you start storing data in it. That way it's not difficult to make changes to the structure of your database at a later time. In this example we'll create a very simple database that will secure your information by asking users to login in for access and create a table that will store and display links to favorite websites.

Setting Up Your Database Using Microsoft Access


You need to have Microsoft Access to create a table needed store login access information. Open Access, select new blank database, save your new database to your PC and then click on the icon to create a new table with the columns needed to store your login data. I would suggest columns named "username", "password", "FirstName", "LastName" and information you would like to gather at login. I usually add information that will carry from one page to the next to customize form features. Now when "Joe Smith" logs in the information is sent to the server to match against the database. If it is incorrect then a message is displayed letting the user know they need to re-enter the information into the form. If correct then they are sent to the next page on the site where you might fill out a form or other information might be displayed. The information that you store in the login table can determine how information is displayed to the user. An example would be that "Joe Smith" is from Idaho; stored with his information is a column called "State" with "ID" stored as the state he resides in. When Joe logs into your website you can create a session which stays with him while logged into your site. This allows you to create smart forms that can be customized depending on your needs. Now you can have the form display information such as the cities for Idaho because you know this person is located in that state. You could also do this such as displaying the page in a larger font by creating a table of user preferences.

Information on how to create tables using Microsoft Access can be found on the Microsoft website:
Click Here

Next time I'll talk about hosting your database and explain how to make the connection between your database and your pages.

Web Guy Guru Recommends: