ASP Classic Response buffer exeeded error - asp-classic

This code was working up until today now I keep getting the buffer exceeded error. I'm positive there is a much better way to do this but I have no idea how.
What I'm trying to do is display any entry from the current date to two weeks out. Users can enter any date within that two week period and the table will fill the spaces in between or after with a default "GREEN" span. I had it working until today. I haven't touched it in three weeks and I have no idea what happened. I'm a lowly graphic designer who's bosses don't know the difference between html/css and asp/sql driven applications. Please help before I go insane...
<div class="cond_holder">
<div class="dir_name">PEDS CARDIOLOGY</div>
<%
Dim this_day_peds_cardio
this_day_peds_cardio = Date
Dim Conditions_peds_cardio
Dim Conditions_peds_cardio_cmd
Dim Conditions_peds_cardio_numRows
Set Conditions_peds_cardio_cmd = Server.CreateObject ("ADODB.Command")
Conditions_peds_cardio_cmd.ActiveConnection = MM_webdbs_STRING
Conditions_peds_cardio_cmd.CommandText = "SELECT * FROM dbo.ryg_conditions WHERE aoc='1' AND Day >= DATEADD(dd, DATEDIFF(dd, 0, GETDATE()), 0) ORDER BY aoc ASC, Day ASC"
Conditions_peds_cardio_cmd.Prepared = true
Set Conditions_peds_cardio = Conditions_peds_cardio_cmd.Execute
Conditions_peds_cardio_numRows = 0
Dim Repeat_peds_cardio__numRows
Dim Repeat_peds_cardio__index
Repeat_peds_cardio__numRows = 14
Repeat_peds_cardio__index = 0
Conditions_peds_cardio_numRows = Conditions_peds_cardio_numRows + Repeat_peds_cardio__numRows
While ((Repeat_peds_cardio__numRows <> 0) AND (NOT Conditions_peds_cardio.EOF))
If DateDiff("d", (Conditions_peds_cardio.Fields.Item("Day").Value), this_day_peds_cardio)=0 Then
%>
<span class="daily_condition <%=(Conditions_peds_cardio.Fields.Item("ryg").Value)%>">
<span style="display: none;"><%=(Conditions_peds_cardio.Fields.Item("aoc").Value)%></span>
<%=(Conditions_peds_cardio.Fields.Item("ryg").Value)%>
<span class="reason"><%=(Conditions_peds_cardio.Fields.Item("reasoning").Value)%></span>
</span><!-- /.daily_condtion -->
<%
this_day_peds_cardio = DateAdd("d", 1, this_day_peds_cardio)
Else
While DateDiff("d", (Conditions_peds_cardio.Fields.Item("Day").Value), this_day_peds_cardio)<>0
%>
<span class="daily_condition GREEN">GREEN</span><!-- SPACER -->
<%
this_day_peds_cardio = DateAdd("d", 1, this_day_peds_cardio)
Wend
%>
<span class="daily_condition <%=(Conditions_peds_cardio.Fields.Item("ryg").Value)%>">
<span style="display: none;"><%=(Conditions_peds_cardio.Fields.Item("aoc").Value)%></span>
<%=(Conditions_peds_cardio.Fields.Item("ryg").Value)%>
<span class="reason"><%=(Conditions_peds_cardio.Fields.Item("reasoning").Value)%></span>
</span><!-- /.daily_condtion -->
<%
this_day_peds_cardio = DateAdd("d", 1, this_day_peds_cardio)
End if
Repeat_peds_cardio__index=Repeat_peds_cardio__index+1
Repeat_peds_cardio__numRows=Repeat_peds_cardio__numRows-1
Conditions_peds_cardio.MoveNext()
Wend
While loop_ctr_peds_cardio < 14
%>
<span class="daily_condition GREEN">GREEN</span><!-- FILLER -->
<%
loop_ctr_peds_cardio = loop_ctr_peds_cardio +1
Wend
%>
</div><!-- /#cond_holder -->

When I read your source code, I came up with two thinks:
You use too many script tags (<% %>), even to seperate vbscript code. This overusing makes it hard to read and understand your code. I had to paste your source code into Notepad++ to tidy up and reading your code.
You didn't use a recordset for the first while query. If you want loop through a result of a Selectquery use the recordset object. It is more convinence to handle and prevents some general errors. Does the using of a recordset eleminate your error?
To your problem:
Do you use an IIS6.0 or higher? If so then following ideas could help (I got it from a german! site of Microsoft, posted in stackoverflow.com (see here). The idears are:
Using Response.Flush()
Turn the Response.Buffer off on the page, or on the entire site.
Response.Buffer = False at the top of the page before any ASP code.
Increase the size of the buffer (see the link on 'see here' position).
Decrase the size of your response.

The reason your response buffer is overflowing is because you have more data to show now. The quickest way to get it sorted should be to issue a Response.Flush every couple of rows or so (depending on how big the response buffer is) inside your while loop. Turning off the response buffer will almost always result in the page taking longer to render, especially if you have lots of context switches like you do.

Related

Trouble with "string.contains" function

I am writing a web form that has a unique travelID per travel request. (see blank column in picture below, I'm not high enough reputation to embed the picture in here)
Some of the travel requests have attached documents and others do not. I wrote this code:
Dim dirs As String() = Directory.GetFiles("E:\DomainWebs\Intranet\fileups\TravelDocs\")
Dim i As Integer = 0
For Each GridRecord As GridRecord In TravelWebDataGrid.Rows
For Each doc As String In dirs
If doc.Contains(TravelWebDataGrid.Rows(i).Items(10).Value) = True Then
TravelWebDataGrid.Rows(i).Items(11).Value = True
End If
Next
i += 1
Next
Just for testing, only the top Travel Request has documents attached. As you can see, it is checking the second row checkbox as well even though it doesn't have any documents attached.
This is what is being compared to row 2:
"DocName" - E:\DomainWebs\Intranet\fileups\TravelDocs\RONNIEP20180124141116-Hello.docx
"TravelID" - RONNIEP20180124135357
Does anyone know why it is doing this? Let me know if you need any more information. Thanks in advance for your responses.
This might be off because I haven't worked with a datagrid but it looks like the code has been over-complicated with the counter. Can you do this?
' you're looping gridrecords/rows.
For Each GridRecord As GridRecord In TravelWebDataGrid.Rows
For Each doc As String In dirs
' use the gridrecord here, not rows(i).
If doc.Contains(GridRecord.Items(10).Value) = True Then
' and here.
GridRecord.Items(11).Value = True
End If
Next
Next

Second Dynamic DIV over writes first dynamic DIV

I have searched for almost three days now and I can't find an answer to this question. As I am somewhat new to ASP.Net I am not sure what the problem is.
Here is the situation. I have an aspx page that has a web form on it. When this form loads it has two SQL queries that execute and populate different controls.
My problem lies not with the queries but creating dynamic DIV tags and adding controls to them. If the query returns one or no records everything is fine. but if there are 2 or more records returned I only end up with the last record being displayed.
When I view the page source (from the browser) I can see the DIV tag ID that was created last, but the first DIV tag is gone. It is like the first DIV tag gets over written or something. I have no idea as to why or what is causing this.
Can anyone help please?
Here is my code:
While (incCounter <= rowCount)
DivName.ID = ("rev" & Convert.ToString(incCounter)) 'Create Div name of rev and the current counter number ex. rev1
review_comments.Controls.Add(DivName) 'Add DIV to web form
rName = (rName & Convert.ToString(incCounter)) 'Create name control name
rDate = (rDate & Convert.ToString(incCounter)) 'Create date control name
rComments = (rComments & Convert.ToString(incCounter)) 'Create comment control name
DivName.Controls.Add(New LiteralControl("<br />"))
DivName.Controls.Add(rRevByLabel)
rNameTextBox.ID = rName
DivName.Controls.Add(rNameTextBox)
DivName.Controls.Add(nbSpace)
DivName.Controls.Add(nbSpace)
DivName.Controls.Add(nbSpace)
DivName.Controls.Add(nbSpace)
DivName.Controls.Add(nbSpace)
DivName.Controls.Add(nbSpace)
DivName.Controls.Add(nbSpace)
DivName.Controls.Add(rDateLabel)
DivName.Controls.Add(rDateTextBox)
DivName.Controls.Add(New LiteralControl("<br />"))
DivName.Controls.Add(rCommentLabel)
DivName.Controls.Add(rCommentsTextBox)
'Assign data from query to new textboxes
rNameTextBox.Text = dtR.Rows(incCounter - 1)("reviewed_by_name").ToString()
rDateTextBox.Text = dtR.Rows(incCounter - 1)("reviewed_by_date").Date()
rCommentsTextBox.Text = dtR.Rows(incCounter - 1)("review_comments").ToString()
rName = "revName"
rDate = "rDate"
rComments = "revComments"
incCounter += 1
End While
I know all the variables are set up correctly because it shows me the last record.
What stupid thing am I doing?

ASP, Forms and passing variables between frames

I am pretty new to ASP, I know VBScript reasonably well though. What I am trying to do is create a website with 2 frames. In the top frame, it asks for a year (from a selection box) and a week number (from a selection box). It should then display the dates relating to the selection and a button to process the request. When the button is clicked the bottom form then processes a SQL query based on the selection in the top frame and displays the info.
Now, my problem is when it comes to understanding ASP. With ASP, all the code is processed then the output is sent to the browser. How do you update variables or even pass them to other frames when the code has already processed?
I just need some pointers on the way forward to accomplishing the above.
Thanks
First off, don't use frames: they're annoying, ugly, and outmoded.
You can do something like this in asp, but it's going to require a round trip (or two) to the server.
The basic outline of the page (let's call it thispage.asp) would be something like
<html><head>[head stuff]
<%
dim yr, wk, i
yr = request.form("Year")
wk = request.form("Week")
'- if you use form method='get', then use request.querystring("Year")
if not isnumeric(yr) then
yr = Year(date) 'or whatever else you want to use as a default
else
yr = CInt(yr)
end if
'similar validation for wk
%>
</head>
<body>
<form method="post" action="thispage.asp">
<select name="Year" size="1">
<%
for i = Year(Date) - 2 to Year(Date) + 2
response.write "<option value='" & i & "'"
if i = yr then response.write " selected"
response.write ">" & i & "</option>"
next
%>
</select> [similar code for week or date or whatever]
<input type="submit">
</form>
<%
If yr <> "" and wk <> "" Then
'- look up stuff in database and output the desired data
'- (this part will be much longer than this)
Else
Response.Write "<p>Please make your selections above.</p>"
End If
%>
</body></html>
If you need to output form fields that are dependent on the user's initial year & week selections, then you're going to need more than one trip to the server, but it's still the same idea: set up the variables you're going to need, see if they have values, write out the form, and then if all the necessary variables have all the necessary values, then you can do your output stuff.

Dynamic variables in Classic ASP

I'd like to know what is the exact code for dynamic variable from link and have it set via conditions of If and If else.
let say i have link of default.asp?variable=value&string=number
how can i get this into my page with coding it in conditional term. (not sure if my code is correct)
<%
DIM value = something
If blah-blah then
[asp code here]
else if blah-blah then
[another asp code here]
end if
%>
i have to match a dynamic value on If and Else If, something like that.
thanks in advance...
I'm going to assume your question is about ASP classic and that you're going to handle:
default.asp?cmd=add&x=5&y=4
default.asp?cmd=mult&x=5&y=4
And, respectively, you want the outputs to be
Answer is 9
Answer is 20
The ASP for that would be something like:
<html>
<head>
<title>simple asp</title>
</head>
<body>
<%
Dim cmd, x, y
cmd = Request.QueryString("cmd")
x = CDbl(Request.QueryString("x"))
y = CDbl(Request.QueryString("y"))
Select Case cmd
Case "add"
Response.Write("Answer is " & (x + y))
Case "mult"
Response.Write("Answer is " & (x * y))
Case Else
Response.Write("Please supply a valid cmd")
End Select
%>
</body>
</html>
get idea from this line of codes
<%
Set udrmcatgry=TheDB.Execute("SELECT * FROM rmcatgry ORDER BY sl asc")
Do while Not udrmcatgry.eof=true
myqsl=udrmcatgry("sl")
TheDB.Execute "Update `rmcatgry` set catnme`='"&request.form(""+myqsl+"")&"' where sl='"&myqsl&"' "
udrmcatgry.MoveNext
Loop
%>

Classic ASP Array not returning values, error 500

I'm working on executing the same code several times to produce a table. My first thoughts went out to using an array to do this.
Here is what i have got so far:
Dim iRow
iRow = 0
'alternate color for rows
Do While Not rsGlobalWeb.EOF
If iRow Mod 2 = 0 Then
response.write "<tr bgcolor=""#FFFFFF"">"
Else
response.write "<tr bgcolor=""#EEEEEE"">"
End If
'some other code
SqlBackup = "SELECT * FROM CMDBbackup WHERE Naam_Cattools = '" & rsGlobalWeb("Device_name") & "'"
Set rsBackup = Server.CreateObject("ADODB.Recordset")
rsBackup.Open SqlBackup, dbGlobalWeb, 3
'declaration of array
Dim fieldname(5),i
fieldname(0) = "Device_name"
fieldname(1) = "Image"
fieldname(2) = "Backup"
fieldname(3) = "Uptime"
fieldname(4) = "Processor"
fieldname(5) = "Nvram"
For i = 0 to 5
If rsGlobalWeb(fieldname(i)) <> "" Then
response.write("<td>" & rsGlobalWeb(fieldname(i)) & "</td>")
Else
If Not rsBackup.EOF Then
If Not IsNull(rsBackup(fieldname(i))) And (rsBackup(fieldname(i)) <> "") Then
response.write("<td>" & rsBackup(fieldname(i)) & " (backup)</td>")
End if
Else
response.write("<td>No data found</td>")
End if
End if
Next
response.write("</tr>")
iRow = iRow + 1
rsGlobalWeb.MoveNext
Loop
The issue i have now is that the following error occurs even tho i have friendly messages turned off:
"500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed."
The logfile shows the following:
"DaEngineSDB.asp |58|800a000d|Type_mismatch 80 -" Where the 58 is the line with the Dim Fieldname.
Without the array it does show the remainder of the code (i have 1 other field which gets added). If i remove the array and fill the fieldname(i) with a normal string value it also works fine.
I was trying out stuff that google says but after attempting several things i am still running up to a wall.
Any ideas what it could be?
Thanks in advance,
Erik
First you should turn on error displaying in your iis, or read the error log for its description, google it if not sure how.
Without error description, it's way too difficult to check what is wrong.
Problem solved!
After banging my head against the wall for a day i found out that i stupidly declared the array inside the DO WHILE loop. Moved the declaration out of it and problem solved.

Resources