• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 552
  • Last Modified:

Session Variables die well before time set in web.config

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
cwickens
Asked:
cwickens
  • 6
  • 6
1 Solution
 
cwickensAuthor Commented:
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
 
cwickensAuthor Commented:
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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
copyPasteGhostCommented:
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
 
cwickensAuthor Commented:
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
 
copyPasteGhostCommented:
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
 
cwickensAuthor Commented:
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
 
copyPasteGhostCommented:
<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
 
cwickensAuthor Commented:
Thanks!
0
 
cwickensAuthor Commented:
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
 
copyPasteGhostCommented:
you are welcome. thanks for the grade
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now