Link to home
Start Free TrialLog in
Avatar of vanauden
vanaudenFlag for Canada

asked on

Use a cookie to store a recordset in order to peruse through it multiple times (ASP and MS SQL Server 2000)

Context (do not need help on this part):

I am building a bingo game using an HTML form and submit buttons for the bingo numbers
Each submit button is paired with a hidden field with the same value as it's paired submit button
if a button is pressed, it's value is submitted and so are all the hidden values
I retrieve the button value only when the save is done the first time
if a button is pressed and there is a value in the DB for another button,
Then I retrieve both the button's submitted value and any hidden values that had already existed in the DB

That is my background info if you are interested.

The Problem: I will have to cycle through all the questions each time a button is pressed. I could do this with multiple queries, but I don't want to, because  I am trying to reduce an already considerable load off the DB server.

What I am thinking of doing is querying for all the questions and current answers and putting the recordset into a local cookie. This cookie would be set to exist for one minute (less if it was possible). I would then seach the cookie for my specific questions and answers.

The question: is using a cookie in this way a stupid thing to do? it seems to me that operations on a local computer are far preferable to operations on a server. I already tried an array, but I can't make it work, so I don't want to talk about that.

I just need to know if my cookie idea is out to lunch or if you think it would work quickly and efficiently.

I figure that my bottleneck would be saving each recordset item to the cookie then looking in the cookie for each item seperately.

What say you, oh mighty ones? :-)







Avatar of vanauden
vanauden
Flag of Canada image

ASKER

hmmm... Maybe I should use session variables for the time it takes to do the comparing and then eliminate them... that might be prety fast and clean...

any thoughts?? compared to a cookie???
crap...I need session vars for other things...so doing a session abondon is out of the question...any other ways to clear a session var without cleaning them all out at once? and also...is the minimum amount time a cookie can exist 24 hours (one day)?  how can I set it lower??
dang it! I think I'm back to using an array...but I can't figure the friggin logic!!!!! arrrgghhh!

What do I do?

array, cookie, session var, or multiple queries...

I have about 135 buttons per page. so that would mean 135 lookups each time a submit is done on the page.
wait a second!! What if I qury the db for all the questions numbers and related answers for the entire page. Then I put the recordset into a 2-dimentional array using rs.GetRows. Then I concatenate the question number with the answer and place each concatenation in a new  1-dimentional array.

Now if I want to know if a particular question has an answer in the DB/array, all I have to do is search for a concatenation of the question number and the answer in the 1-dim array!!

Of course I may be entirely and absolutely wrong! Mothereffingcrap! I have to try this! (even though I'm kinda dizzy right now)
having trouble moving the concatenation to the new 1-dim array...
ok 1-dim array done... still testing...
I give up - can't make it work with an array.

SOLUTION
Avatar of sukumar_diya
sukumar_diya
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of solution46
solution46

vanauden,

first off: not only are cookies unreliable (as mentioned earlier, the user may have them switched off) but you're probably going to run out of storage space in them if you try to copy a recordset into them).

one thing comes to mind about this. For the bingo game, you are presumably generating a random number (calling it) every few seconds or so?
If so, how about the following...

1) store the called number as an application variable
2) store the x,y co-ordinates of each button on the form, so that the x co-ord, y co-ord and 'picked' value are passed back when the user clicks a button.
3) build logic in your com layer that checks a session level array of picked numbers for a winning sequence (e.g. line, cross, house, whatever).
4) Each time the user selects a number by clicking on a button, check that value against the current 'called' number in the application variables. If the number is correct, add it to a session level array of picked numbers. Apply the logic in 3) above to check for a winning sequence.
5) Render the form appropriately.

Not sure how you'll handle polling to let the user know the called number has changed but I'd have thought a simple java applet should be able to handle that.


Hopw this helps,

s46
Why not just make a stored procedure that does this. Passed it takes the question number, the answer and user. It returns the next question. Something like this:

usp_GetQuestion
@user varchar(8),
@answer int =-1,
@question int,

as
 IF @answer<>-1
 INSERT INTO TABLENAME VALUES(@question,@answer, @user)

select @question=question +1 from tablenbame where user=@user

return @question



<b>sukumar diya and/or solution46</b> - If I used session varibales for this, would it be too much for the server if there were 120 session variables in a page? In other words, does the NUMBER of session vars matter? Is there a way to clear SPECIFIC session vars and not others?

MichaelSFuller- this would mean that I would have about 120 calls to db each time a form button is clicked (there are 120 on a page)




Would this work to clear the specific session vars after the user has finished using the page?

to clear specific sesson vars and not others:

1- place the session vars you wish to keep in an ASP variable
2- clear the full session (Session.Abandon)
3- put the variable you kept, back into a session var

please see my previous comment as well...there is a question in there I need answered.
Oh your doing it that way...server side cookies would make sense then.
----> Oh your doing it that way...server side cookies would make sense then.


how do you do this... can you give a simple example of creating the cookie on the server side, as well as eliminating them or timing them out?
Your time out is set in the web config.

Like this is VB.net to set a cookie
'set the cookie
FormsAuthentication.SetAuthCookie(txtUsername.Text, False)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you all for the help!

However, I need to clarify something.

From what I understand, server-side cookies are a misnomer and should actually be refered to as session variables.

see- https://www.experts-exchange.com/questions/21190722/ASP-server-cookies.html#12469019

I will be putting my recordset in session variables.

thank you