Got a database? ASPs take it to the Web

Why are many webmasters turning to Microsoft Internet Information Server? For dynamic cross-platform Web page delivery through Windows NT's Active Server Page technology. Like Common Gateway Interface programs, ASPs use server-side scripts to make pages interactive. Unlike most CGIs, ASPs embed the scripting code within Hypertext Markup Language code.

Why are many webmasters turning to Microsoft Internet Information Server? For dynamic
cross-platform Web page delivery through Windows NT's Active Server Page technology.


Like Common Gateway Interface programs, ASPs use server-side scripts to make pages
interactive. Unlike most CGIs, ASPs embed the scripting code within Hypertext Markup
Language code.


When a user requests a page called info.asp, for example, a script embedded in info.asp
executes before it leaves the server. The user will see only the surrounding HTML code.


The scripts are server-side, so it makes no difference which browser the user has. The
code simply executes and passes standard HTML code to the browser.


Developers who write ASP code within HTML code do their work in one file, making it
easier to plan and visualize the final screen.


ASP script is almost by default Visual Basic Script, although you can write the scripts
in Microsoft JavaScript, Java or even C++.


ASPs work best with Internet Information Server 3.0 or 4.0. They also run under
Microsoft's Personal Web Server and Mac OS' Personal Web Sharing. But remember that a
personal Web server, though fine for developing or testing ASPs, is not robust enough to
serve pages to a large audience.


To learn ASP skills, you must have a strong grasp of HTML. It helps to know a scripting
language, too. Although you can use other languages to program ASPs, I recommend Microsoft
VBScript. Microsoft products, not coincidentally, tend to work best with other Microsoft
products.


If you have a good understanding of JavaScript or another scripting language, VBScript
will not be hard to learn. An excellent VBScript tutorial and reference guide appear at http://www.microsoft.com/vbscript/.


Several Microsoft applications can create ASPs. For example, Access 97 can publish live
databases online quickly and easily. It is short on options for customization, though.


Microsoft FrontPage also can create ASP code. But I have heard that FrontPage sometimes
clobbers the code enough to render it useless. If you use ASPs with FrontPage, take the
precaution of inserting the ASP code as a FrontPage HTML component.


Microsoft's Visual InterDev is the most professional tool for creating Web
applications. Like Visual Basic, InterDev sets up a work space to which a programmer adds
objects and code for Web applications.


InterDev works best under Windows NT 4.0. It generates code that automates the work of
building a cutting edge site. You probably will need to fall back on your trusty text
editor for the final tweaks, however. HomeSite from Allaire Corp. of Cambridge, Mass., is
my editor of choice. It generates no code, but it does recognize ASP code and has buttons
for adding ASP delimiters or server variables.


ASP follows Microsoft's object model, familiar to Visual Basic programmers. Several
built-in objects have methods and properties for adding functions to a page.


The Application object manages states and information for any Web application created
with ASP. Take out the Web element, and a Web application is like any other application.
The most common Web applications so far are online commerce software and chat engines.


The Session object manages information about user Web sessions. The object sends and
receives cookies that track time, preferences and progress through a site. Information
given when a user first enters the site is readily available to any other page on the
site.


The Response object sends information to the client or user. The Server object adds
functions to ASPs. ActiveX components created using Visual Basic or C++ expand the
functions.


Several components are part of the package. The most useful are a browser capabilities
component, a file-access component and a database-access component. Many third-party
components are available, too.


Here's how ASP's ActiveX data object lets you integrate a database with a Web page: A
Structured Query Language command passes from the ASP code through the ActiveX Data Object
to the database. The database retrieves the information requested by the SQL command and
passes it back to the Active Server Page for display in HTML form.


But to start with, the server must know which database it is going to use. This is
where the Open Database Connectivity Data Source Control Panel comes in.


On the control panel, the user gives the database a name, which will appear in the ASP
scripts. Once the server knows about the database, a connection must be established
between the Active Server Page and the database. The code appears at the beginning of an
ASP document before the HTML:


<%
Set DbConn=Server.CreateObject
("ADODB.Connection")
DbConn.Open ("DSN=Contacts;")
%>


The expression Server.CreateObject ("ADODB.Connection") tells the Server
object to make a connection using the ActiveX Data Object component. This results in an
object called DbConn that will be used only for this page. The object opens a connection
with a database referred to above as Contacts--the name given to it in the ODBC Data
Source Control Panel.


Once the connection is established, we can do something with it:


<%
SQL="SELECT * FROM Customers
ORDER BY State"
Set RS=DbConn.execute(SQL)
%>


The SQL statement returns all the data in the Customers table of the Contacts database.
The ORDER BY statement causes the data to be sorted by the State field.


The next line passes the SQL statement to the ActiveX Data Object using the DbConn
object. This retrieves data from the database and creates a record set called RS, a
temporary local copy of the retrieved information.


Now we must output the record set in the body of the HTML document:


<Body>
<%
Do While NOT RS.EOF
%>
<li><b><%=RS ("Name") %></b><br>
<%=RS ("Address") %><br>
<%=RS ("City") %>, <%=RS ("State")
%> &nbsp;<%=RS("Zip") %>
<hr width="180" align="left">
<%
RS.Movenext
loop
%>
</BODY>


The third line is VBScript that begins a while loop. The loop tells the server to do
certain things until it encounters the end of file of the record set. <%= is shorthand
for Response.write, so the sixth line writes out the value of the Name field in the record
set.


Because there are <b> tags around the ASP code, the result of that code will
appear as bold text. The lines that follow do the same for other fields in the record set.
A horizontal rule separates the records.


The RS.Movenext statement tells the code to move to the next record in the record set.
The loop statement starts the whole process over again with the new record.


Once the loop is done and any other ASP code on the page executes, the results go back
to the user who requested the data. If the user looks at the source code of the page, only
HTML appears.


This tutorial only touches on what you can do with Active Server Pages. Two good books
on the subject are Using Active Server Pages from Que Publishing and Professional
Active Server Page Programming
from Wrox Press.


The first book, good for beginners, devotes many chapters to working with and
integrating databases. The second book, written for programmers, covers all the ground.


Many Web sites offer ASP tips, tutorials and articles.


For starters, take a look at the following Web sites: http://www.activeserverpages.com/, http://www.microsoft.com/workshop/server/default.asp,
http://www.serverobjects.comand http://www.activexserver.com.


Jason Hart is a webmaster and analyst at Advanced Management Technology Inc. in
Washington.


NEXT STORY: NASA meets via switched nets

X
This website uses cookies to enhance user experience and to analyze performance and traffic on our website. We also share information about your use of our site with our social media, advertising and analytics partners. Learn More / Do Not Sell My Personal Information
Accept Cookies
X
Cookie Preferences Cookie List

Do Not Sell My Personal Information

When you visit our website, we store cookies on your browser to collect information. The information collected might relate to you, your preferences or your device, and is mostly used to make the site work as you expect it to and to provide a more personalized web experience. However, you can choose not to allow certain types of cookies, which may impact your experience of the site and the services we are able to offer. Click on the different category headings to find out more and change our default settings according to your preference. You cannot opt-out of our First Party Strictly Necessary Cookies as they are deployed in order to ensure the proper functioning of our website (such as prompting the cookie banner and remembering your settings, to log into your account, to redirect you when you log out, etc.). For more information about the First and Third Party Cookies used please follow this link.

Allow All Cookies

Manage Consent Preferences

Strictly Necessary Cookies - Always Active

We do not allow you to opt-out of our certain cookies, as they are necessary to ensure the proper functioning of our website (such as prompting our cookie banner and remembering your privacy choices) and/or to monitor site performance. These cookies are not used in a way that constitutes a “sale” of your data under the CCPA. You can set your browser to block or alert you about these cookies, but some parts of the site will not work as intended if you do so. You can usually find these settings in the Options or Preferences menu of your browser. Visit www.allaboutcookies.org to learn more.

Sale of Personal Data, Targeting & Social Media Cookies

Under the California Consumer Privacy Act, you have the right to opt-out of the sale of your personal information to third parties. These cookies collect information for analytics and to personalize your experience with targeted ads. You may exercise your right to opt out of the sale of personal information by using this toggle switch. If you opt out we will not be able to offer you personalised ads and will not hand over your personal information to any third parties. Additionally, you may contact our legal department for further clarification about your rights as a California consumer by using this Exercise My Rights link

If you have enabled privacy controls on your browser (such as a plugin), we have to take that as a valid request to opt-out. Therefore we would not be able to track your activity through the web. This may affect our ability to personalize ads according to your preferences.

Targeting cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising.

Social media cookies are set by a range of social media services that we have added to the site to enable you to share our content with your friends and networks. They are capable of tracking your browser across other sites and building up a profile of your interests. This may impact the content and messages you see on other websites you visit. If you do not allow these cookies you may not be able to use or see these sharing tools.

If you want to opt out of all of our lead reports and lists, please submit a privacy request at our Do Not Sell page.

Save Settings
Cookie Preferences Cookie List

Cookie List

A cookie is a small piece of data (text file) that a website – when visited by a user – asks your browser to store on your device in order to remember information about you, such as your language preference or login information. Those cookies are set by us and called first-party cookies. We also use third-party cookies – which are cookies from a domain different than the domain of the website you are visiting – for our advertising and marketing efforts. More specifically, we use cookies and other tracking technologies for the following purposes:

Strictly Necessary Cookies

We do not allow you to opt-out of our certain cookies, as they are necessary to ensure the proper functioning of our website (such as prompting our cookie banner and remembering your privacy choices) and/or to monitor site performance. These cookies are not used in a way that constitutes a “sale” of your data under the CCPA. You can set your browser to block or alert you about these cookies, but some parts of the site will not work as intended if you do so. You can usually find these settings in the Options or Preferences menu of your browser. Visit www.allaboutcookies.org to learn more.

Functional Cookies

We do not allow you to opt-out of our certain cookies, as they are necessary to ensure the proper functioning of our website (such as prompting our cookie banner and remembering your privacy choices) and/or to monitor site performance. These cookies are not used in a way that constitutes a “sale” of your data under the CCPA. You can set your browser to block or alert you about these cookies, but some parts of the site will not work as intended if you do so. You can usually find these settings in the Options or Preferences menu of your browser. Visit www.allaboutcookies.org to learn more.

Performance Cookies

We do not allow you to opt-out of our certain cookies, as they are necessary to ensure the proper functioning of our website (such as prompting our cookie banner and remembering your privacy choices) and/or to monitor site performance. These cookies are not used in a way that constitutes a “sale” of your data under the CCPA. You can set your browser to block or alert you about these cookies, but some parts of the site will not work as intended if you do so. You can usually find these settings in the Options or Preferences menu of your browser. Visit www.allaboutcookies.org to learn more.

Sale of Personal Data

We also use cookies to personalize your experience on our websites, including by determining the most relevant content and advertisements to show you, and to monitor site traffic and performance, so that we may improve our websites and your experience. You may opt out of our use of such cookies (and the associated “sale” of your Personal Information) by using this toggle switch. You will still see some advertising, regardless of your selection. Because we do not track you across different devices, browsers and GEMG properties, your selection will take effect only on this browser, this device and this website.

Social Media Cookies

We also use cookies to personalize your experience on our websites, including by determining the most relevant content and advertisements to show you, and to monitor site traffic and performance, so that we may improve our websites and your experience. You may opt out of our use of such cookies (and the associated “sale” of your Personal Information) by using this toggle switch. You will still see some advertising, regardless of your selection. Because we do not track you across different devices, browsers and GEMG properties, your selection will take effect only on this browser, this device and this website.

Targeting Cookies

We also use cookies to personalize your experience on our websites, including by determining the most relevant content and advertisements to show you, and to monitor site traffic and performance, so that we may improve our websites and your experience. You may opt out of our use of such cookies (and the associated “sale” of your Personal Information) by using this toggle switch. You will still see some advertising, regardless of your selection. Because we do not track you across different devices, browsers and GEMG properties, your selection will take effect only on this browser, this device and this website.