?
Solved

Session Variables die well before time set in web.config

Posted on 2008-10-09
12
Medium Priority
?
547 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

800 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