thiazi
08-24-2006, 05:28 PM
Hi all,
The code below is pulling information from a basic phone list database. It's restricted with javascript so you have to enter a few alpha characters, so that way you cannot pull the whole database at one time.
However, when several users start using it at once, the w3wp.exe process in IIS hits 95% and causes the CPU usage to hit 100%, making all sites on the server extremely slow.
Do you guys see anything wrong from a code standpoint?
<%@ Language=VBScript %>
<% Option Explicit %>
<% Server.ScriptTimeout = 90 %>
<!-- #include file="adovbs.inc" -->
<%
On Error Resume Next
If Err.Number <> 0 then
ReportError Err.Description
Error.Clear
End If
Sub ReportError
Response.Write("An error has occured, please notify Helpdesk. Error: " & Err.Description)
End Sub
Dim SecHeader
SecHeader = InStr(1, Request.ServerVariables("HTTP_REFERER"), "PhoneSearch.html",1)
If SecHeader = 0 or SecHeader = Null Then
Response.Write("Invalid Referrer.")
Response.Write("Invalid HTTP REFERER " & Request.ServerVariables("HTTP_REFERER"))
Response.End()
End If
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "DSN=dsbdbname;UID=usergoeshere;PWD=passgoeshere"
objConn.Open
Dim iLoca
Dim iFname
Dim iLname
Dim iDept
Dim iZone_Cube
Dim iext
iLoca = Trim(Replace(UCASE(Request("LOCA")),"'","''"))
iFName = Trim(Replace(UCASE(Request("FNAME")),"'","''"))
iLName = Trim(Replace(UCASE(Request("LNAME")),"'","''"))
iDept = Trim(Replace(UCASE(Request("DEPT")),"'","''"))
iZone_Cube = Trim(Replace(UCASE(Request("ZONE_CUBE")),"'","''"))
iext = Trim(Replace(UCASE(Request("EXT")),"'","''"))
Dim strSQL
strSQL = "SELECT * FROM AIST.V_CONTACT_DETAILS WHERE (1=1)"
If iLoca <> "" Then
strSQL = strSQL & " AND (UPPER(LOCA) LIKE '%" & iLoca & "%')"
End If
If iFname <> "" Then
strSQL = strSQL & " AND (UPPER(FNAME) LIKE '%" & iFname & "%')"
End If
If iLname <> "" Then
strSQL = strSQL & " AND (UPPER(LNAME) LIKE '%" & iLname & "%')"
End If
If iDept <> "" Then
strSQL = strSQL & " AND (UPPER(DEPT) LIKE '%" & iDept & "%')"
End If
If iZone_Cube <> "" Then
strSQL = strSQL & " AND (UPPER(ZONE_CUBE) LIKE '%" & iZone_Cube & "%')"
End If
If iext <> "" Then
strSQL = strSQL & " AND (EXT LIKE '%" & iext & "%')"
End If
strSQL = strSQL & " ORDER BY LNAME"
Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSql, objConn
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Phone List Search Results</title>
<% Response.CacheControl = "no-cache" %>
<% Response.AddHeader "Pragma", "no-cache" %>
<% Response.Expires = -1 %>
<body link="#ffffff" vlink="#ffffff" alink="#ffffff" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" >
<div align="left">
<table width="100%">
<tr>
<td width="100%" colspan="3" align="center">
<br>
</td>
</tr>
<tr>
<td width="1%" align="center" valign="top">
</td>
<td width="24%" align="left" valign="top">
</td>
Phone List Search Results
</table>
<table border="1" align="center" style="text-align: left">
<tr bgcolor="#cccccc">
<th>Prefix</th>
<th>Phone Number</th>
<th>Extension</th>
<th>Last/Surname</th>
<th>First</th>
<th>Department</th>
<th>Title</th>
<th>Location</th>
<th>Zone/Cube</th>
<th>Fax</th>
<th>Mobile</th>
<th>Pager</th>
<th nowrap="nowrap">E-Mail</th>
</tr>
<%
Do While Not objRS.EOF
Response.Write "<tr>"
Response.Write "<td nowrap='nowrap'>" & objRS("PREFIX") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("PHONE") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("EXT") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("LNAME") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("FNAME") & " </td>"
Response.Write "<td>" & objRS("DEPT") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("TITLE") & " </td>"
Response.Write "<td width='100'>" & objRS("LOCA") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("ZONE_CUBE") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("FAX") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("MOBILE") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("PAGER") & " </td>"
Response.Write "<td nowrap='nowrap'><a id=""colorhyperlink"" href=mailto:" & objRS("email") & ">" & objRS("email") & "</a> </td>"
Response.Write "</tr>"
objRS.MoveNext
Loop
%>
</table>
<%
Response.write "<div style=""display: none"">Query string used for this output: " & strSql & "</div>"
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>
</td></tr>
</table>
</body>
</html>
The code below is pulling information from a basic phone list database. It's restricted with javascript so you have to enter a few alpha characters, so that way you cannot pull the whole database at one time.
However, when several users start using it at once, the w3wp.exe process in IIS hits 95% and causes the CPU usage to hit 100%, making all sites on the server extremely slow.
Do you guys see anything wrong from a code standpoint?
<%@ Language=VBScript %>
<% Option Explicit %>
<% Server.ScriptTimeout = 90 %>
<!-- #include file="adovbs.inc" -->
<%
On Error Resume Next
If Err.Number <> 0 then
ReportError Err.Description
Error.Clear
End If
Sub ReportError
Response.Write("An error has occured, please notify Helpdesk. Error: " & Err.Description)
End Sub
Dim SecHeader
SecHeader = InStr(1, Request.ServerVariables("HTTP_REFERER"), "PhoneSearch.html",1)
If SecHeader = 0 or SecHeader = Null Then
Response.Write("Invalid Referrer.")
Response.Write("Invalid HTTP REFERER " & Request.ServerVariables("HTTP_REFERER"))
Response.End()
End If
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "DSN=dsbdbname;UID=usergoeshere;PWD=passgoeshere"
objConn.Open
Dim iLoca
Dim iFname
Dim iLname
Dim iDept
Dim iZone_Cube
Dim iext
iLoca = Trim(Replace(UCASE(Request("LOCA")),"'","''"))
iFName = Trim(Replace(UCASE(Request("FNAME")),"'","''"))
iLName = Trim(Replace(UCASE(Request("LNAME")),"'","''"))
iDept = Trim(Replace(UCASE(Request("DEPT")),"'","''"))
iZone_Cube = Trim(Replace(UCASE(Request("ZONE_CUBE")),"'","''"))
iext = Trim(Replace(UCASE(Request("EXT")),"'","''"))
Dim strSQL
strSQL = "SELECT * FROM AIST.V_CONTACT_DETAILS WHERE (1=1)"
If iLoca <> "" Then
strSQL = strSQL & " AND (UPPER(LOCA) LIKE '%" & iLoca & "%')"
End If
If iFname <> "" Then
strSQL = strSQL & " AND (UPPER(FNAME) LIKE '%" & iFname & "%')"
End If
If iLname <> "" Then
strSQL = strSQL & " AND (UPPER(LNAME) LIKE '%" & iLname & "%')"
End If
If iDept <> "" Then
strSQL = strSQL & " AND (UPPER(DEPT) LIKE '%" & iDept & "%')"
End If
If iZone_Cube <> "" Then
strSQL = strSQL & " AND (UPPER(ZONE_CUBE) LIKE '%" & iZone_Cube & "%')"
End If
If iext <> "" Then
strSQL = strSQL & " AND (EXT LIKE '%" & iext & "%')"
End If
strSQL = strSQL & " ORDER BY LNAME"
Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSql, objConn
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Phone List Search Results</title>
<% Response.CacheControl = "no-cache" %>
<% Response.AddHeader "Pragma", "no-cache" %>
<% Response.Expires = -1 %>
<body link="#ffffff" vlink="#ffffff" alink="#ffffff" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" >
<div align="left">
<table width="100%">
<tr>
<td width="100%" colspan="3" align="center">
<br>
</td>
</tr>
<tr>
<td width="1%" align="center" valign="top">
</td>
<td width="24%" align="left" valign="top">
</td>
Phone List Search Results
</table>
<table border="1" align="center" style="text-align: left">
<tr bgcolor="#cccccc">
<th>Prefix</th>
<th>Phone Number</th>
<th>Extension</th>
<th>Last/Surname</th>
<th>First</th>
<th>Department</th>
<th>Title</th>
<th>Location</th>
<th>Zone/Cube</th>
<th>Fax</th>
<th>Mobile</th>
<th>Pager</th>
<th nowrap="nowrap">E-Mail</th>
</tr>
<%
Do While Not objRS.EOF
Response.Write "<tr>"
Response.Write "<td nowrap='nowrap'>" & objRS("PREFIX") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("PHONE") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("EXT") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("LNAME") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("FNAME") & " </td>"
Response.Write "<td>" & objRS("DEPT") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("TITLE") & " </td>"
Response.Write "<td width='100'>" & objRS("LOCA") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("ZONE_CUBE") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("FAX") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("MOBILE") & " </td>"
Response.Write "<td nowrap='nowrap'>" & objRS("PAGER") & " </td>"
Response.Write "<td nowrap='nowrap'><a id=""colorhyperlink"" href=mailto:" & objRS("email") & ">" & objRS("email") & "</a> </td>"
Response.Write "</tr>"
objRS.MoveNext
Loop
%>
</table>
<%
Response.write "<div style=""display: none"">Query string used for this output: " & strSql & "</div>"
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>
</td></tr>
</table>
</body>
</html>