Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Caching a recordset???
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 15 December 2004 :  08:47:47  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
Ok on a clients website I have a dynamically generated menu system, with one top level and two sub-levels, as the website grows so does the menu.

Every now and then now when I visit the site, I get an error saying "System resources exceeded" - thats not good, I want to avoid that.

The error message cuts right into the middle of the menu code, so I know thats why its doing it.

The menu code consists of 3 recordsets, which could probably be cleaned up a little bit. Maybe you guys can help me out with this. The code is below, I want to either a) Avoid hitting the database each time a page loads or b) downsize this into 1 recordset if possible


Sub makeMenu()
strsql = "SELECT SITE_ID, SITE_NAME FROM W_SITE ORDER BY SITE_NAME ASC"
set rs = Server.CreateObject("ADODB.RecordSet")
set rs1 = Server.CreateObject("ADODB.RecordSet")
set rs2 = Server.CreateObject("ADODB.RecordSet")
topI = 0
rs.Open strsql, kConn
  do while not(rs.eof)
    response.write("oCMenu.makeMenu('top" & topI & "','','" & rs("SITE_NAME") & "','site.asp?type=site&id=" & rs("SITE_ID") & "','')" & vbNewline)
    subI = 0
    strsql = "SELECT CAT_ID, CAT_TITLE FROM W_CAT WHERE SITE_ID=" & rs("SITE_ID") & " ORDER BY CAT_TITLE ASC"
    rs1.Open strsql, kConn
      if not(rs1.eof) then
        do while not(rs1.eof)
          response.write(" oCMenu.makeMenu('sub" & topI & subI & "','top" & topI & "','" & rs1("CAT_TITLE") & "','site.asp?type=category&id=" & rs1("CAT_ID") & "')" & vbNewline)
            strsql = "SELECT PAGE_ID, PAGE_TITLE FROM W_PAGE WHERE CAT_ID=" & rs1("CAT_ID") & " ORDER BY PAGE_TITLE ASC"
            rs2.Open strsql, kConn
              subSubI = 0
              if not(rs2.eof) then
                do while not(rs2.eof)
                  response.write("    oCMenu.makeMenu('sub" & topI & subI & subSubI & "','sub" & topI & subI & "','" & rs2("PAGE_TITLE") & "','site.asp?type=page&id=" & rs2("PAGE_ID") & "')" & vbNewline)
                subSubI = subSubI + 1
                rs2.movenext
                loop
              end if
            rs2.Close
          subI = subI + 1
        rs1.movenext
        loop
      end if
    rs1.close
  topI = topI + 1  
  rs.movenext
  loop
rs.Close
set rs = nothing
set rs1 = nothing
set rs2 = nothing
End Sub


And now I get no output at all, just the system resources exceeded :(

-Stim

Edited by - Da_Stimulator on 15 December 2004 09:06:23

pdrg
Support Moderator

United Kingdom
2897 Posts

Posted - 15 December 2004 :  09:32:52  Show Profile  Send pdrg a Yahoo! Message
hey D_S - i think the nested loops will kill you here - not read the code too closely, but it looks like for each record in rs, you hit the db for rs1, then for each record in that you hit it for rs2...so if rs = 5 records, rs1 = 5 records and rs2 = 5 records (say) then rs2 is opened 25 times and rs1 5 times...no wonder you're running out of resources - heck I would run out of resources, to be honest

Go to Top of Page

dayve
Forum Moderator

USA
5820 Posts

Posted - 15 December 2004 :  10:24:54  Show Profile  Visit dayve's Homepage
this looks very familiar. I believe based on the snippet of code you're using that it is
Cool Menus from DHTMLCentral (another forum I moderate at). Although I haven't touched
Cool Menus in a long time, I do recall using it in a database and Thomas Brattli over at
DHTML Central posted some tutorials using the menus with a database. Here is a demo link:

http://www.dhtmlcentral.com/projects/coolmenus/examples/asp-example/vbscript.asp

If you have more questions concerning this menu, I strongly suggest asking the crew over
at DHTML Forums. We have a category specifically for Cool Menus here:

http://www.dhtmlcentral.com/forums/default.asp?CAT_ID=3



Edited by - dayve on 15 December 2004 10:25:22
Go to Top of Page

davemaxwell
Access 2000 Support Moderator

USA
3020 Posts

Posted - 15 December 2004 :  10:42:34  Show Profile  Visit davemaxwell's Homepage  Send davemaxwell an AOL message  Send davemaxwell an ICQ Message  Send davemaxwell a Yahoo! Message
Stim, Stim, Stim

Didn't we teach you anything? At the very least, use getrows and process the stuff as an array.

A better choice would be to put all the code in one SQL statement and process it all at once (with getrows of course ). This code isn't tested, but it should work...


Sub NewmakeMenu()
	' dim local variables...
	dim site_id, site_name, cat_id, cat_title, page_id, page_title
	dim hold_site_id, hold_cat_id
	dim topI, subI, subSubI

	strSQL = "SELECT N.site_id, N.site_name, C.cat_id, C.cat_title, page_id, page_title" & _
		 "  FROM SITE_NAME N LEFT JOIN W_CAT C ON C.site_id = P.site_id LEFT JOIN W_PAGE P ON C.cat_id = P.cat_id" & _
		 " ORDER BY n.site_name ASC, c.cat_title, p.page_title"
	set rs = Server.CreateObject("ADODB.RecordSet")
	rs.Open strsql, kConn

	if rs.EOF and rs.BOF then
		' no records found.
		recCount = -1
	else
		arrRecSet = rs.getrows(-1)	:	recCount = UBound(arrRecSet, 2)
	end if
	rs.Close	:	set rs = nothing

	topI = 0
	for i = 0 to recCount
		' move to local for readability....
		site_id = arrRecSet(0, i)		:	site_name = arrRecSet(1, i)
		cat_id = arrRecSet(2, i)		:	cat_title = arrRecSet(3, i)
		page_id = arrRecSet(4, i)	:	page_title = arrRecSet(5, i)
		if site_id <> hold_site_id then
			response.write("oCMenu.makeMenu('top" & topI & "','','" & site_name & "','site.asp?type=site&id=" & site_id & "','')" & vbNewline)
			hold_site_id = site_id	:	topI = topI + 1	:	hold_cat_id = ""	:	subI = 0
		end if
		if len(cat_id) > 0 then
			if cat_id <> hold_cat_id then
				response.write(" oCMenu.makeMenu('sub" & topI & subI & "','top" & topI & "','" & cat_title & "','site.asp?type=category&id=" & cat_id & "')" & vbNewline)
				hold_cat_id = cat_id	:	subI = subI + 1	:	subSubI = 0
			end if
			if len(page_id) > 0 then
				response.write("    oCMenu.makeMenu('sub" & topI & subI & subSubI & "','sub" & topI & subI & "','" & page_title & "','site.asp?type=page&id=" & page_id & "')" & vbNewline)
				subSub = subSub + 1
			end if
		end if		
	next
End Sub

Dave Maxwell
Barbershop Harmony Freak
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 15 December 2004 :  10:54:08  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
quote:
Originally posted by dayve

this looks very familiar. I believe based on the snippet of code you're using that it is
Cool Menus from DHTMLCentral (another forum I moderate at). Although I haven't touched
Cool Menus in a long time, I do recall using it in a database and Thomas Brattli over at
DHTML Central posted some tutorials using the menus with a database. Here is a demo link:

http://www.dhtmlcentral.com/projects/coolmenus/examples/asp-example/vbscript.asp

If you have more questions concerning this menu, I strongly suggest asking the crew over
at DHTML Forums. We have a category specifically for Cool Menus here:

http://www.dhtmlcentral.com/forums/default.asp?CAT_ID=3





Yes, its coolMenus - I have no problem with coolmenus itself, just the asp code I wrote to go along with it :P

And I've posted on the support forums over there, only to see my topic go to page 3 in about 2 weeks without a single reply.

quote:

Stim, Stim, Stim

Didn't we teach you anything? At the very least, use getrows and process the stuff as an array.

A better choice would be to put all the code in one SQL statement and process it all at once (with getrows of course ). This code isn't tested, but it should work...


lol

I'll give your code a try, thx for producing that

-Stim
Go to Top of Page

Da_Stimulator
DEV Team Forum Moderator

USA
3373 Posts

Posted - 15 December 2004 :  11:03:38  Show Profile  Send Da_Stimulator an AOL message  Send Da_Stimulator a Yahoo! Message
Code didnt work dave, got the following error:

Microsoft JET Database Engine error '80040e14'

Syntax error (missing operator) in query expression 'C.SITE_ID = P.SITE_ID LEFT JOIN W_PAGE P ON C.CAT_ID = P.CAT_ID'.

-Stim
Go to Top of Page

dayve
Forum Moderator

USA
5820 Posts

Posted - 15 December 2004 :  11:30:27  Show Profile  Visit dayve's Homepage
stim, did you review the link to the code I posted? it uses the GetRows method as Dave also pointed out...

http://www.dhtmlcentral.com/projects/coolmenus/examples/asp-example/vbscript.asp

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.41 seconds. Powered By: Snitz Forums 2000 Version 3.4.07