Solved

Session Variables die well before time set in web.config

Posted on 2008-10-09
12
546 Views
Last Modified: 2013-11-08
I store a userid in a session variable and 2 of my pages have updatepanels that refresh with an asp:timer, these pages, and a few without the timer, do not maintain the session variable and pass "NULL" when a commandbutton for DB update is passed.

I am fairly new to .NET (about a year) and never had this issue with classic ASP sessions.
<authentication mode="Forms">
      <forms timeout="60" cookieless="AutoDetect" loginUrl="default.aspx" defaultUrl="tb_main_menu.aspx" />
    </authentication>
      <sessionState cookieless="AutoDetect" timeout="60" />

Open in new window

0
Comment
Question by:cwickens
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 22682279
0
 
LVL 5

Author Comment

by:cwickens
ID: 22687929
It show (and all the examples show) use of a sqldatabaseconnection in the web.config.

Ok, that brings up another question, if I switch to stateServer mode, is this connection needed and if not, is this the connection to my app's DB or is there a default db used by the process?
0
 
LVL 5

Author Comment

by:cwickens
ID: 22687990
the other question, which may be the root cause, is: If I have a timer on the page (AJAXControlToolkit, asp:timer) and when the timer fires, the updatePanel on the page updates, does that count as an activity that will keep the session alive?
0
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 22688015
using the stateServer mode will solve your session dissapearing problem

for your dbv connection use this: in your web.config

<connectionStrings>
            <add name="DBConnection" connectionString="Data Source=SERVERIP;Network Library=DBMSSOCN;Initial Catalog=MYDBNAME;User ID=MYDBUSERNAME;Password=MYDBPASSWORD;"
        providerName="System.Data.SqlClient" />
      </connectionStrings>

then when you want to use this code in your C#: do this:

connString = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
0
 
LVL 13

Accepted Solution

by:
copyPasteGhost earned 500 total points
ID: 22688073
0
 
LVL 5

Author Comment

by:cwickens
ID: 22688089
I gues I must be making this more difficult than I need to, but, is this a separate connection from the one I already have to my 'live' database?

Sorry for the braindead appearance of the question, however, I have been debugging this application after going to production and this is the only issue I have left to resolve...5 days and counting with about 3 hours of sleep a night, I am running on coffee at this point.  :)
0
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 22688124
if you already have a connection why are we trying to make a new one?

leave that code out. I thought you needed to know how to make a connection string in your web.config.....

I'm in the same situation! (Sleep Deprivation) Deadlines are fun!

Hope that clearifies things. If not ask away I'm here.
0
 
LVL 5

Author Comment

by:cwickens
ID: 22688262
ok, that helps, so just to bring it back around...

I can leave the session state in the web.config to default and include the jscript/aspx page from the link you sent and basically be done, right?
-OR-
If I use stateserver, I can leave out the reference to the sqldatabaseconnection in the web.config since the connectionstring is already defined like this:
<sessionState mode="StateServer"
      stateConnectionString="tcpip=SampleStateServer:42424"
      cookieless="false"
      timeout="20"/>
 
<bouncing head off keyboard> 9oo2erhkxaireuadofbi84adf98 </bouncing head off keyboard>
0
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 22688310
<sessionState mode="StateServer"
      stateConnectionString="tcpip=SampleStateServer:42424"
      cookieless="false"
      timeout="20"/>

this stores where the session state is stored.....not a connection to your database....you will need both. or you can lose the session state stuff...unless you need it. (I never include that)

Check here for more info about the session state:  
http://msdn.microsoft.com/en-us/library/system.web.configuration.sessionstatesection.stateconnectionstring.aspx

But besides that...you got it!
0
 
LVL 5

Author Closing Comment

by:cwickens
ID: 31504799
Thanks!
0
 
LVL 5

Author Comment

by:cwickens
ID: 22711581
I wanted to wait until today (after the holiday weekend) to see if there would be any issues with this.

I appear to have resolved this issue and even got 3 solid nights of sleep thanks to your assistance!

V/r,
chuck
0
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 22711593
you are welcome. thanks for the grade
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question