SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    May 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Local Dataset Cache

    I have an ASP Application (website) that I am writing that returns records from an SQL Query to the client. I want to store some of this data at the client for use on other pages, to be used as filtering criteria for later SQL Queries.

    I was hoping to avoid re-posting this data from Form Page for Form Page. Can I somehow cache it on the server in a session cookie (I think thats what it's called), or on the client so that it is accessible?

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Just use Session variables to port data from page to page.

    Code ASP:
    'Page1.asp
    Dim sVar
    sVar = "Joe Bloggs" 'Let us pretend this data has come from the database
    Session("Name") = sVar
     
    'Page2.asp
    Response.Write Session("Name")
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Member
    Join Date
    May 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, but I am lost at how to incorporate this in practice with an undetermine number of recordset rows that is returned in page1.asp; that I need to keep the details of through the session. Please forgive my noviceness; I am a sys-admin much more than I am a developer.

    Code ASP:
    page1.asp
    <%
    While NOT RS.EOF
    %>
        <a href=nextpage.asp?pkey=<%=rs("RecordFK")%>&fkey=<%=rs("RecordPK")%>>
        <%=rs("RecordName")%></a>
    <%
    count = count + 1
    strint = CStr(count)
    pkey = "pkey" & strInt
    fkey = "fkey" & strInt
    name = "name" & strInt
    Session(pkey)=rs("RecordPK")
    Session(fkey)=rs("RecordFK")
    Session(name)=rs("RecordName")
     
    RS.MoveNext
    Wend
    %>
    ---------------------------------------------------------
    nextpage.asp
    <%
    for each .... ' don't know the syntax for this
     
    %>
        <a href=nextpage.asp?pkey=<%=Session("pkey")%>&fkey=<%=Session("fkey")%>><%=Session("name")%></a>
     
    <%
    Next
    %>

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What is page1.asp doing that can't be done in nextpage.asp? To be honest, you don't want to be passing massive amounts of data between the pages - it's much more efficient to just pass a relevant key/reference and run the SQL in nextpage.asp

    But if you want to pass multiple related items, use arrays for the session variables - you're almost there.

    Code ASP:
    <%
    'If you have created the recordset to offer the RecordCount
    'property (or you have retrieved a COUNT value in the SQL)
    numrecs = rs.RecordCount
    Redim aPkey (numrecs), aFkey (numrecs), aName (numrecs)
    While NOT RS.EOF
    %>
        <a href=nextpage.asp?pkey=<%=rs("RecordFK")%>&fkey=<%=rs("RecordPK")%>>
        <%=rs("RecordName")%></a>
    <%
    count = count + 1
    aPkey(count)=rs("RecordPK")
    aFkey(count)=rs("RecordFK")
    aName(count)=rs("RecordName")
     
    RS.MoveNext
    Wend
    Session ("pkey") = aPkey
    Session ("fkey") = aFkey
    Session ("name") = aName
    %>
    ---------------------------------------------------------
    nextpage.asp
    <%
    iCount = Ubound(Session("pkey"))
    For i = 1 to iCount
    '..... do stuff
    Next
    %>

    Useful links ...

    http://asp.codenewbie.com/articles/a...ys-Page_1.html

    http://www.codefixer.com/tutorials/recordcount.asp
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Member
    Join Date
    May 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was researching Session(array) last night. Thank you; you're definately helping me in the right direction.

    To be completely honest; this code is for a student report card; online interface. The school I work for is still in the dark ages with an antiquated Student System that does not have an online report card. I do now; with what I've written, but I am trying to make it more 'intuative' and detailed.

    Environment:
    Backend is FoxPro (don't hate; I'm stuck with it)
    Connection from web-server is UNC to .dbc; 2GB network backbone.

    Performance:
    It was my concern that as 300+ students will probably hit this thing every morning; the fewer queries to the data-tables the better. Not to mention all the faculty in the fat-gui front end taking attendance at the same time.
    The session caching I want to do is the data table primary keys for each class grade-book; so that I can re-present the list of enrolled classes on every page so they can be navigated between; then I only have to query the currently viewed class grade detail from the data-tables. In order to determine the course/class list; I have to open several tables to establish the relationships; and I presume this is a load at the very least in the IIS ASP Worker Process.

    Am I wrong in my thinking about performance?

    The Session Array would store possibly up to 24 rows, with only three columns per row. Each Cell is only about 6 characters in length. (Course Number, Gradbook Student Enrollment Primary Key, Student Foriegn Key).

  6. #6
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tribalsimba View Post
    The Session Array would store possibly up to 24 rows, with only three columns per row. Each Cell is only about 6 characters in length. (Course Number, Gradbook Student Enrollment Primary Key, Student Foriegn Key).
    So that's 3 x 24 x 6 = 432 bytes, plus session overheads, per user. In the grand scheme of things this is not such an issue, even with, say, 500 users - but this would mean the sessions using up 250KB+ of RAM on the web server.

    In an ASP page a database transaction takes milliseconds. So as long as you open up the connection as late as possible, get the data, then close it as early as possible (in the ASP code), then you shouldn't have any issues with multiple users clashing with database access.

    Surely FoxPro can't be any worse than MS Access, which only allows 10 concurrent connections (in real world figures)? Access is used by quite a number of web applications which maybe have up to a 1000 users, and a well-devised application copes well.

    IMHO the way to go is to use sessions to maintain key data (e.g. User ID), then get the main info via SQL calls in the respective pages based on the session values.

    Ian Anderson
    www.siteguru.co.uk

  7. #7
    SitePoint Member
    Join Date
    May 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your expertise is very insightful. Thank you very much... I appreciate your time and comments.

    I'm thinking that the RAM overhead (less than 1MB) on the Web-Application server is severly minimal in the grand scheme of things; and the end result is a faster enumeration of the object page (nextpage.asp); rather than two separate DataSet queries on the page. I am not concerned if the Web-App even consumes 30MB of RAM; as long as it's for performance gains and minimized resource dependancies all around.

    So, is this a good place to find Classic ASP developers for hire with expertise in ADO (Active Directory) and SQL integration? I have a few projects I could spend some money on; and I am sure I am 'inefficient' comparatively.

  8. #8
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If you're looking for ASP developers then maybe try the Marketplace here at SitePoint?

    If you happened to wish to send me your requirements (see link in my sig) then I could always take a look and say if I was interested/capable.
    Ian Anderson
    www.siteguru.co.uk

  9. #9
    SitePoint Member
    Join Date
    May 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, so the goal here is the following, but I'm sure my Syntax is weak.

    Code ASP:
    nextpage.asp
    <%
    iCount = Ubound(Session("pkey"))
    For i = 1 to iCount
    '..... do stuff
     
    Response.Write "<a href=?pkey=" & Session("pkey") & "&fkey=" & Session("fkey") & ">" & Session("name") & </a>
     
    '..... end of stuff
    Next
    %>

  10. #10
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If you used the array method I showed earlier, just do the reverse to get at the array values.

    Code ASP:
    aPkey = Session ("pkey")
    aFkey = Session ("fkey")
    aName  = Session ("name")
    iCount = Ubound(aPkey)
    For i = 1 to iCount
      '..... do stuff
     
      Response.Write "<a href=?pkey=" & aPkey(i) & "&fkey=" & aFkey(i) & ">" & aName(i) & "</a>"
     
      '..... end of stuff
    Next
    Ian Anderson
    www.siteguru.co.uk

  11. #11
    SitePoint Member
    Join Date
    May 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, so we're running. The Session variables to carry to the next page. In order to use the array's I had to declare them in nextpage.asp. When I declared them as dynamic array's (ie. aPkey() ) it did not like that. I had to declare and refer to the arrays as just the name of the array ( ie. aPkey ).

    Being the extrordinary novice at programming as I am; there is no way I would have known this, and I'm still not sure I truely understand they why or how its different. But that's OK; I'm good with being a novice, and just doing what is expected.

    So one issue I have is that the session values seem to get lost after about 1 minute. So when I go from page1.asp to nextpage.asp; the array is successfully parsed. But if I refresh nextpage.asp after about 60 seconds; the array is empty. Where is the setting to determine the timeout of the session data?

  12. #12
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    To define the size of the arrays in nextpage.asp ...

    Code:
    iSize = Ubound(Session("pkey"))
    Redim aPkey(iSize), aFkey(iSize), aName(iSize)
    ... but just creating them simply by assigning their values as the Session arrays is fine.

    Session timeout is 20 minutes by default in IIS. This is read/set using Session.Timeout
    Ian Anderson
    www.siteguru.co.uk

  13. #13
    SitePoint Member
    Join Date
    May 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •