Migrating a Web Server to IIS 5.0

Previous Topic Next Topic

External Gateway and Database Logic

CGI applications were originally created to give Web clients access to applications outside the Web environment. Most CGI applications interface with databases of some sort, and many CGI applications are used to access services such as electronic mail servers. This section describes techniques for using ASP to access databases and other external services.

Databases

Microsoft® ActiveX® Data Objects (ADO) is a database access method you can use within the ASP environment. ADO is designed to be highly efficient in a multithreaded environment, where many instances of the ADO code execute simultaneously. Thus, ADO is ideal for Web applications, particularly when they need to scale to many concurrent users.

ADO exposes an object model to abstract the ideas of connecting to, and executing commands against, a remote database. The database need not support SQL, but if it doesn’t, a database-specific piece of software called an OLE DB provider is required. If your database vendor supplies an ODBC driver for your database, you can use a provider for ODBC data sources that is supplied with IIS 5.0.

Perl developers commonly access a database by using a package such as Dbperl or the more current DBI package. No special package is required within the ASP environment. For example, the following simple ASP page, written in PerlScript. uses the ODBC data source ADOSamples to dump the contents of a table called “Orders”:

<%@ LANGUAGE=PerlScript %>
<HTML>
  <BODY>
    <P>
    <%
       $Conn = $Server->CreateObject("ADODB.Connection");
       $Conn->Open( "ADOSamples" );
       $RS = $Conn->Execute( "SELECT * FROM Orders" );
    %>
    <TABLE BORDER=1>
    <TR>
    <%
       $count = $RS->Fields->Count;
       for ( $i = 0; $i < $count; $i++ )
    {
          %><TD><B><%= $RS->Fields($i)->Name %></B></TD><%
       }; %> </TR> <%
       while ( ! $RS->EOF ) 
    {
          %> <TR> <%
          for ( $i = 0; $i < $count; $i++ ) 
    {
             %><TD VALIGN=TOP>
             <%= $RS->Fields($i)->value %></TD><%
          };
          %> </TR> <%
          $RS->MoveNext;
       };
       $RS->Close;
       $Conn->Close;
       %>
    </TABLE>
  </BODY>
</HTML>

An additional benefit of working within the ASP environment is the ability to take advantage of Component Services. Not only does Component Services provide support for process isolation, as discussed previously, it also enables developers to easily build scalable Web applications based on components. Component Services takes care of all the plumbing issues such as transactions, connection management, and thread management, thus freeing the developer to concentrate primarily on building business logic.

For more information about ADO and Component Services, see Data Access and Transactions in this book and see http://www.microsoft.com/com/.

For more general information about ADO, ODBC, and Microsoft’s overall data access strategies, see http://www.microsoft.com/data/.

For more information about the Perl-based DBI package and for documentation, including ideas for porting existing DBI code to the Win32 platform, see http://www.symbolstone.org/.


© 1997-1999 Microsoft Corporation. All rights reserved.