Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with session variables

Status
Not open for further replies.

ctdapper

Programmer
Feb 13, 2001
22
0
0
US
I have written a local intranet program so that users can chech the status of different projects.
I use session variables to keep tract of the project number and the phasecode of the project they are viewing. How ever if there are more then two users then the one that changes the project number that change takes place to anyother users web page.

example first user is looking up project 10 phase 6 and the second user logs on and wants to look up progect 33 phase 3 then users ones project and phase also becomes 33 and 6.

Am I missing something about session variables or is there something wrong somewhere?


Thanks,

Dan
 
I think you may be missing what session variables are. A set of session variables is created for each session that is started. A session being whenever a new browser instance connects to the website.

Sessions cannot talk to each other that I know of. You could accomplish this by storing the current project/phase in the database. Or you could use application variables. I haven't used application variables myself although I believe they work the same way as sessions, except for the fact that there is only one set of them for the entire application no matter how many users.

Hope this cleared things up for you. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Mark,

Maybe I did not explain myself correctly. When user two starts a session then changes to a different project number the project number changes for all browsers that are connected to the site.

I have a search that button that the user can enter in the project number then on the click event it does the following steps.
sets a pram for a stored procedure to make a query in the DB. then sets the session variable.

some code
session("project") = tbtown.text
.....parameters("@project").value = session("project")

some code

If I searched. say project 159
if the person next to me browsed to the website his town would come up with 159.
then if he searched on 300 my project would become say 300.

Most of all it is noticable when I try to to go to the next project. session("project")=session("project")+1

I may be using project 1 put it will go to 326 because some one searched on project 325.


I hope you can shed a little more light on this.



Dan
 
I am still not clear on what you are asking. Are you asking how to implement this/or have you implemented it and your having problems.

If you are asking how to do it, then like I said in the first post you can't with sessions.

Using your example of the guy (lets call him Joe) next to you at a different computer. You searched up project 159. If you put this into a session variable like so.. session("project") = somevariable '=159
Joe sits down and opens a browser his session doesn't even have a variable called "project" yet because it is a completely different session.

However, if instead of session("project") = somevariable '=159 You had Application("project") = somevariable '=159. Then Joes application variable will be set to 159.

I am not sure if we are on the same page quite yet so I will wait for further clarification from you before I go off. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Mark,

We are on the same page.
My session variables are acting as if they are application variables.

When a person enters the site thier session("project") is set to session("project")=1
session("user") = tbuser.text

the next person who logs in resets all the current session data for eveybody to that users data. then when ever some one changes any session("vars") then that session variable is changed for all users.

sessionState mode = "InProc"
cookieless = "true"
does not work
and
sessionState mode = "InProc"
cookieless = "false"
does not work

I need to have all users use thier own variables.
I have no application variables and cache one small data table when the application starts for the first time each day that clears its self at the end of each work day.
this problem is killing me.

Thanks
Dan





 
[sunshine]Oh you don't want this overwriting of variables to happen but it is? Have I understood you now??

I thought you were trying to get this to happen, not prevent it. Your entire scenario makes alot more sense to me now. I am however, going to have to do some research since I haven't heard of sessions doing this.

If you could provide some additional info it would make things easier.
Could you post the code you use to set the session variables.
What kind of environment is this happening in? ie. Server and client types.
Also, for debugging purposes print out the session id number somewhere on the page. It should be different for the different users. It sounds like the new user isn't getting his own session.
Thats all I have for now. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Mark,
I am new to this web based stuff with dotnet so I will be happy with any help.

The Session ID will not print out. I have now lost the use of all session Veriables. However The sqlserver database is keeping track of each session.

Platform 2000 server IIS5.0 SQL 2000
development platform asp.net

I don't know if Im missing something here or not.
If I'm using the SQL server to keep track of all the session variables then I should see them somewhere Correct?

If I stick this line of code in it does not work at all.

It is now looking like I can not access any type of session anything. such as count timeout or mode properties.


Dan











 
I can't see any code there Dan.

Anywho do you have VS? If so then go to the following address ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconsessionstate.htm
Otherwise goto MSDN.microsoft.com and search for Session State.

It explains how session state works. At the very bottom of the article it explains how to set up your sessions to use either a state server, or sql server to store your session data.

You were talking about the sessionstate mode before. Was that in web.config that you were changing values? If not then that is were you need to be. For now I might sugggest using InProc sessions until your site has the traffic to justify a sqlsessionState. The SQL and state server are more usefull when using a web farm and such. You may have heard all this before but in case you haven't you can say you heard it from me. Heh heh!
Hope that article does it for ya. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Mark,

Thanks for all the time.
I have searched the microsoft site all day yesterday and today trying to get this to work.

Yes in the config.
I have tried both the inproc and the SQL neither will work.

This works the first time thriugh called when a page loads

Public Sub fill_data()
Dsallwos1.Clear()
Dssummary1.Clear()
Dspcms1.Clear()
Dstown1.Clear()
Me.SqlSelectCommand1.Parameters("@town_id").Value=Session("town")
Me.SqlSelectCommand1.Parameters("@project_id").Value = Session("project")
Me.SqlSelectCommand2.Parameters("@town_id").Value = Session("town")
Me.SqlSelectCommand2.Parameters("@project_id").Value = Session("project")
Me.SqlSelectCommand3.Parameters("@town_id").Value = Session("town")
Me.SqlSelectCommand4.Parameters("@town_id").Value = Session("town")
Me.SqlSelectCommand4.Parameters("@project_id").Value = Session("project")
Me.SqlConnection1.Open()
Me.Sqlallwos.Fill(Dsallwos1)
Me.Sqlsummary.Fill(Dssummary1)
Me.Sqltown.Fill(Dstown1)
Me.Sqlpcms.Fill(Dspcms1)
Me.SqlConnection1.Close()
End Sub

This will work for a search.

Private Sub Bgo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bgo.Click
Bcancel.Visible = False
Bgo.Visible = False
Session("town") = Trim(TextBox36.Text)
Session("project") = Trim(TextBox37.Text)
TextBox36.Visible = False
TextBox37.Visible = False
Call fill_data()
Call display_data()
End Sub

But if some one enters the site the sessions will get reverted back.

This does not work anymore I tried diferent items with the code so that is why it looks like this.
this is used so that the user can move to the next project
Public Sub update_activedata(ByVal a As integer)
Dim b As Integer
b = 1
b = CInt(session("activerow"))
b = b + a
session("activerow") = CStr(b)
If b > 0 Then
Session("town") = (dsactiveprojects.Tables(0).Rows(b).Item(0))
Session("project") = (dsactiveprojects.Tables(0).Rows(b).Item(1))
End If

End Sub


thanks
Dan.paradis@snet.net
Dan.paradis@po.state.ct.us

 
Dan a quick note. I don't see the "activerow" session variable setup anywhere. You may be setting this elsewhere, if not it may be why the 3rd method doesn't work. As to the messed up session I can't seem to find anything on this either.
Could i see the section of your web.config that isn't working? That is the only place I can think of that is screwed up. Unless, there is a wrongly configured option in IIS or the .Net framework itself.

mmm One thing you could try is to make a fresh webtester project and see if some simple session things will work there.
Do you need to use sessions for this or is there something else you could use ie. Query Strings ...

If anyone else out there has any ideas please post them.
If you do solve this Dan please post so that this question does have a solution. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
K...I just read the entire post and have come to two conclusions:

1. I still have no clue what ctdapper is trying to do/prevent

2. Dammit Mark, its AnyHOO!!!
:p

But seriously, ct, could you explain (no code, no geek speak) what it is you're trying to do. It could be that we need to rethink the design, but it'll be easier if we understand what hte application is supposed to accomplish


D

 
D

The application allows users to track different phases of a project(a building project). The contractor can look a different areas of the project for the status of the job and the of funds aviable/committed to that phase. I am tring to use session variables to keep tract of the project and phase the user is working with. So that when he/she moves to a different page the project/phase goes with him. there are 10 different pages to this site each page displays different information about each process and funding of the project. If there is only one user logged in the program works great. If anybody else logs in then all the session variables get reset and that user will start with the current users project number. In other words if there are 30 users loged in when ever someone changes a phase or project number it changes for all users logged in. The session variables are acting like application variables and I am unable to stop this from happening. Mark wanted to see some of the code so that he can see the way I am setting my session variables.

If you can add to this please do so. Thanks

Dan
 
Hey Dan,

Too funny: we're both working on similar projects (mine's a job management system for a roofing company, where they need to track projects and all the quotes, workorders, and invoices for the project).

Ok, the session thing is wanky, so maybe lets try and rule out some possibilities:
1. Create a dummy page in the same project. Put a textbox and a button on it, and have it so that if the user clicks the button, whatever is in the textbox gets saved to some session variable. Then test out the page (either two sessions, or better yet have a buddy access it at the same time you are) and see if the session variable can be re-written by either of you.

If 1 = "Yes, it can overwrite"
then we'll need to look at your config (as having
session vars act like global vars is crazy stuff)
if 1 = "No, the session variables aren't shared"
then we'll have to look at your code and try and
figure out if possibly, somehow, there is information
set to a global place that is being accessed by all
users (you mentioned a datatable created as an
Application variable. What does it hold, and what is
saved there?)

Test that out, and let us know what happens. We'll be in better shape to trouble shoot from there.

:)

D
 
D,

First thing Monday I will check it out. The project is a work and I try not to work at home unless I researching such as this.


Thanks

Dan
 
I am unable to set a session variable. and retrive that session veriable.

Please advise.


Thanks
 
say WHA?!

So you mean that if you do this on a page:

Session("SomeVar") = "Hello"
Label1.Text = Session("SomeVar")

that nothing shows up in Label1?!

Have you checked that your IIS is running?

D
 
D,

Yes I say that.

I went through and deleted all session variables. and gave them a application variable(I don't want to do this but I only want to check to ensure that everything worked.) It work just like the origanal problem. After deleting all session variables. Then I retried the little test I set it on one page and displayed it on another. Success.

Then I replaced all the application variables with new session variables. It worked the first time in.

How ever when I tried to log in from another workstation it did not work. When I ended the first session and went back in that to failed.

I am at wits end.


Dan



 
Hmmm...

K, another test:

Start a brand new project (new virtual directory, the whole bit)

Try your test there. If it does the same thing, then we know for sure its something wrong with IIS.

If it does work, then there's something with your project thats funky, and we can look at those posibilities.

D
 
Everything worked fine. with the new project I made two simple pages that wouls display the session variable and change it. it worked just fine.


Dan


 
K, well thats good though: we know that its not IIS, and that its something with your project.

Just curious: what are your settings under Sessionstate in your web.config? (don't worry about the IP stuff, just the mode/cookieless, etc.)

D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top