« Previous Next »

Thread: ASP pages bogged down with too much server side code

Last post 03-04-2009 4:59 PM by shawn.bordeaux. 7 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (8 items)

Sort Posts:

  • 03-03-2009, 2:29 PM

    ASP pages bogged down with too much server side code

    I have a few web applications that I have created using ASP classic. My problem is that some of the pages require running multple recordsets so the data can be used to run another recordset which stores the data which is ultimatley being accessed. In other words something like this;


     <%

    Set Rs = Server.CreateObject("ADODB.Recordset") 
    SQL_Select1 = "SELECT idnumber from users WHERE idnumber IS NOT NULL"
    if not rs.eof Then
    do while not rs.eof
    Set R2 = Server.CreateObject("ADODB.Recordset")
       SQL_Select2 = "SELECT reques_id from current_user_entries WHERE idnumber='&Rs("idnumber")"
    if not rs2.eof Then
    do while not rs2.eof
        Set Rs3 = Server.CreateObject("ADODB.Recordset")  
              SQL_Seect3 = "SELECT * from catalog_merchandise WHERE productid='&Rs2("requeted_id") "
    if not rs3.eof Then
    do while not rs3.eof
    ' process stuff here including INSERT into table...
    rs3.movenext
    rs3.loop
      End If
    rs2.movenext
    rs2.loop
      End If
    rs.movenext
    loop
      End If

    %>

    Well anyways this is not really my code but just an example. I also run A LOT of IF Statements to check the data and assign appropriate variables. Some of my pages are nearly 1000 lines of asp code doing this.

    On top of that, all the records I am loading I then have to insert them into another table and the load times are extremley long. Any advice or tips of things I can do to speed up the server load time? Can any code likes this be done on client side?
    I can upload or copy and paste some of my real code so if anyone here is up to the task of looking it over and giving me some advise on more efficient ways of writing these pages I would greatly appreciate it. Keep in mind I am fairly new at this. I have created quite a few web apps in ASP without any real structured training. Just on things I've picked up on the way.

    Thank you in advance!

    Best regards,

    Shawn

     

  • 03-03-2009, 6:13 PM In reply to

    Re: ASP pages bogged down with too much server side code

    Hello,

    No, this could not be done on client side. You could also check for hints in http://forums.asp.net , the same login as here.

    Regards

  • 03-03-2009, 6:16 PM In reply to

    Re: ASP pages bogged down with too much server side code

    Thank you!

    Isn't there a cleaner and more efficient way to open all of these record sets? It seems like I have a lot of open connections at one time and since they are all looping off the first record set I can't close them until everything is complete.

  • 03-04-2009, 7:35 AM In reply to

    • tomkmvp
    • Top 10 Contributor
    • Joined on 03-20-2003, 10:27 AM
    • Central NJ
    • Posts 6,189
    • IIS MVPs

    Re: ASP pages bogged down with too much server side code

    Hi Shawn.

    The ASP.NET web site won't be much help as you're using classic ASP.

    Is there a way to use JOIN in your SQL queries to bring back one table of all the data you need?

  • 03-04-2009, 8:48 AM In reply to

    Re: ASP pages bogged down with too much server side code

    I never thought about using JOIN... I will read up on it and give it a try Today. Thank you!

  • 03-04-2009, 9:23 AM In reply to

    Re: ASP pages bogged down with too much server side code

    Okay so I am starting to play around with the JOIN command and here is what I have:
    I am working with 2 tables at the moment. Table 1 = employee and Table 2 = c2z_emp_timecard

     <%
    Sql_select = " SELECT employee.first_name, employee.last_name, employee.filenumber, employee.paygroup, c2z_emp_timecard.date " & _
        " FROM employee " & _
        " INNER JOIN c2z_emp_timecard " & _
        " ON employee.filenumber=c2z_emp_timecard.filenumber " & _
        " ORDER BY employee.last_name "
    Set rs = dataconn.execute(sql_select)
     If not rs.eof Then
     Do while not rs.eof
     response.Write("<Br><Br>"&Rs("date") ' should this be Rs("c2z_emp_timecard.date") ??
    rs.movenext
    loop
    End IF
    rs.close
    %>

    So my question is, is it possible to add a WHERE clause into the JOIN statement Like;

    Sql_select = " SELECT employee.first_name, employee.last_name, employee.filenumber, employee.paygroup, c2z_emp_timecard.date " & _
        " FROM employee " & _
        " WHERE employee.supervisorname='John Doe' " & _
        " INNER JOIN c2z_emp_timecard " & _
        " ON employee.filenumber=c2z_emp_timecard.filenumber " & _
        " ORDER BY employee.last_name "

    If this is not possible I guess I can do an if statement after the results to check if supervisorname ='john doe' but it just seems like a lot of extra records being pulled that I don't need.

    Thank you!
    By the way, I haven't tested the above join statement so if it looks off let me know. Thanks!

     

  • 03-04-2009, 9:35 AM In reply to

    • tomkmvp
    • Top 10 Contributor
    • Joined on 03-20-2003, 10:27 AM
    • Central NJ
    • Posts 6,189
    • IIS MVPs

    Re: ASP pages bogged down with too much server side code

    Yes you can do that.  Not sure if your syntax is correct but you can use a WHERE.

  • 03-04-2009, 4:59 PM In reply to

    Re: ASP pages bogged down with too much server side code

    In case anyone looks this post up in the Future here is the syntax I used; I have the variables paygroup, week1_start and pay_end_date defined from other code before the JOIN statement.

    <%

     Sql_select = " SELECT E.first_name, E.last_name, E.filenumber, E.paygroup, C.date, C.day_in, C.day_out, C.pto_hours " & _
        " FROM employee E " & _ ' notice I am refering to the employee table as E
        " INNER JOIN c2z_emp_timecard C" & _ ' notice I am refering to the other table as C
        " ON E.filenumber=C.filenumber " & _
        " AND C.date BETWEEN '"&payp_week1_start&"' AND '"&pay_end_date&"' " & _
        " AND C.paygroup = E.paygroup " & _
        " AND E.supervisorname='"&supervisorname&"' " & _
        " ORDER BY E.last_name "
      
    Set rs = dataconn.execute(sql_select)

     %>

    Best regards and thanks for the help as always!

Page 1 of 1 (8 items)
Microsoft Communities