Codefixer - ASP tutorials, resources and software
asp.netPRO “Best ASP.NET Host” – DiscountASP.NET
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Wednesday 14 May
MembersPro PayPal - ASP Membership software

ASP.NET 3.5 Hosting – DiscountASP.NET


ASP Partner ASP Partner ASP Partner more partners...

Timing retrieval of database records using Timer Function

The code snippet below places the Timer function at the start of our code and at the end of our code and assigns the seconds returned to variables. Subtracting the StartTime from the EndTime variable will give us the time it takes to execute our code.

<%@ Language="VBScript" %>
<% Option Explicit
'Declare variables
Dim oConnection, oRecordset
Dim sSQL, sConnString, sNewsTitle, sNewsBody
Dim StartTime, EndTime, TimeIt

StartTime = Timer
%>
<html>
<head>
<title>Time our code</title>
</head>
<body>
<%
'declare SQL statement that will query the database
sSQL="SELECT HEADLINE, NEWS_STORY FROM tblNews"

'define the connection string, specify database
'driver and the location of database
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("News.mdb")

'create an ADO connection and recordset
Set oConnection = Server.CreateObject("ADODB.Connection")
Set oRecordset = Server.CreateObject("ADODB.Recordset")

'Open the connection to the database
oConnection.Open(sConnString)

'Open the recordset object, execute the SQL statement
oRecordset.Open sSQL, oConnection

'first of all determine whether there are any records
If oRecordset.EOF Then
Response.Write("There are no news articles.")
Else
'If there are records then loop through the fields
Do While Not oRecordset.EOF
sNewsTitle= oRecordset("headline")
sNewsBody= oRecordset("news_story")
Response.Write "<p>"
Response.Write sNewsTitle & "<br />" 'insert a line break
Response.Write sNewsBody
Response.Write "</p>"
'move on to the next record
oRecordset.MoveNext
Loop
End If

'close the connection and recordset objects and free up resources
oRecordset.Close
oConnection.Close
Set oRecordset = Nothing
Set oConnection = Nothing

EndTime = Timer
TimeIt = EndTime - StartTime
Response.write "Time it took to run our code: " & TimeIt
%>

</body>
</html>





If you have any code snippets to share with full credit given then send an email to Codesnippets - You'll receive full credit and a link back to your site.

ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software