High-Performance Web Sites: ADO versus MSXML 

by Tim Chester

Listing One

<% Language=VBScript %>

<!-- ADO/ASP Model Example Code -->

<%

'////Let's create some objects

    Dim objRecordset, objData

    '///create an adodb recordset object 

set objRecordset = server.createobject("adodb.recordset")

    '///create an instance of my custom data access object

set objData = server.createobject("mydataobject.selectdata")

'///go get some data

strSQL = "Select Title, Year, Term from Courses"

set objRecordset = objData.SelectSQL(strSQL)

    '///now render the top of my HTML table

%>

    <table>

        <tr>

            <td>Title</td>

            <td>Year</td>

            <td>Term</td>

        </tr>

<%

    '///now loop through my recordset to generate my table rows

   Do while objRecordset.eof <> True

%>

        <tr>

            <td><%=objRecordset("Title")%></td>

            <td><%=objRecordset("Year")%></td>

            <td><%=objRecordset("term")%></td>

        </tr>

<%

    objRecordset.MoveNext

    Loop

    '///now finish the bottom of my HTML table

%>

    </table>

<%  

    '///now destroy my objects

    set objRecordset = Nothing

    set objData = Nothing

%>



Listing Two

<% Language=VBScript %>

<!-- XML/XSL Model Example Code -->

<%

'////Let's create some objects

    Dim objData, objXML1, objXML2

     '///create an instance of my custom data access object

set objData = server.createobject("mydataobject.selectdata")



 '///create two instances of the MSXML DomDocument Object

set objXML1 = server.createobject("msxml.domdocument")

set objXML2 = server.createobject("msxml.domdocument")



'///run my parsers in blocking mode 

ObjXML1.async = FALSE   

ObjXML2.async = FALSE



'///set msxml1 to my xml data returned from my data object

'///go get some data, set parser1 to xml data

strSQL = "Select Title, Year, Term from Courses"

objXML1.LoadXML(objData.SelectSQL(strSQL))

objXML2.Load(server.mappath("Courses.xsl"))



'///now transform the xml and xsl and write it to the browser

response.write(objXML1.TransformNode(objXML2))

%>



Listing Three

Public Function SelectSQLStatement(byval 

                   strSQLStatement as String) As adodb.Recordset

    '////public method that executes a sql statement passed as a parameter 



    '//// and returns the results as an ado recordset object create my objects

    dim objConnection as adodb.Connection

    dim objRecordset as adodb.recordset



'///initialize my objects

Set objConnection = New adodb.Connection

        Set objRecordset = New adodb.Recordset

    '///use client side cursor

    objConnection.CursorLocation = adUseClient



'///open connection on connection string

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" 

                    & "Data Source=" & App.Path & "\courses.mdb" 



'////open my recordset on my sql statement

objRecordset.Open strSqlStatement, objConnection, 

              adOpenForwardOnly, adLockReadOnly, adCmdText



 '///disconnect my recordset from my connection

set objRecordset.ActiveConnection = Nothing



'///set recordset to my return object

        Set SelectSQLStatement = objRecordset

    '///close my database connection

        objConnection.Close

    '///destroy my objects

Set objConnection = Nothing

End Function



Listing Four

Public Function SelectSQLStatement(byval strSQLStatement as String) As Variant

    '////public method that executes a sql statement passed as a parameter and

    '///returns the results as an string create my objects

    dim objConnection as adodb.Connection

    dim objRecordset as adodb.recordset

    dim objStream as adodb.stream



'///initialize my objects

Set objConnection = New adodb.Connection

       Set objRecordset = New adodb.Recordset

Set objStream = new adodb.stream

    '///use client side cursor

    objConnection.CursorLocation = adUseClient



'///open connection on connection string

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" 

                           & "Data Source=" & App.Path & "\courses.mdb" 

'////open my recordset on my sql statement

objRecordset.Open strSqlStatement, objConnection, 

                                adOpenForwardOnly, adLockReadOnly, adCmdText



'//persist recordset to xml in stream object

objRecordset.Save objStream, adPersistXML

'///start stream at first position

objStream.Position = 0

    '///return xsl as function output

SelectSQLStatement = objStream.ReadText

'///set recordset to my return object

    '///close my database objects

        objStream.Close

objRecordset.Close

objConnection.Close

    '///destroy my objects

Set objConnection = Nothing

Set objRecordset = Nothing

Set objStream = Nothing



End Function



Listing Five

<%

'///check to see if I have presentation in my cache

'///and how old it is.  if it doesn't exist, or the data is

'///older than 30 minutes I refresh the application object

If isempty(application("AvailableTerms")) or 

   (datediff("n", application("AvailableTermsTimeStamp"), now()) > 30) Then



'///my cache is old or doesn't exist, therefore I just load it

'////create two msxml parsers as before create one data object

set objData = server.createobject("xmlCourses.Select")

set objXML1 = server.CreateObject("MSXML2.DOMDOCUMENT")

set objXML2 = server.CreateObject("MSXML2.DOMDOCUMENT")



'///run my parsers in blocking mode 

ObjXML1.async = FALSE  

ObjXML2.async = FALSE

    

'///load xml data from my data object

objxml1.loadXML(objdata.SelectTermsAvailable()) 



'////load xsl from disk

objxml2.load(server.MapPath("terms.xsl"))



'//now refresh my application object

'//and set a timestamp variable so I know how old my cache is      

Application.Lock

Application("AvailableTerms") = objxml1.transformNode(objxml2)

    Application("AvailableTermsTimeStamp") = now()

    Application.UnLock

        

    '///now destroy my objects

set objXML1 = Nothing

    set objXML2 = Nothing

    set objData = Nothing

End If

    '///now write out my results from the cache if the cache existed and 

    '///wasn't old this would be the only thing to occur on this page

Response.Write(application("availableterms"))

%>  











4



