×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

session variable lost after database connection, even with response.redirect("....", false

session variable lost after database connection, even with response.redirect("....", false

session variable lost after database connection, even with response.redirect("....", false

(OP)
Hi,
I'm having some issues holding a session variable after a response.redirect

The code below works perfectly (the Response.Redirect has the parameter false so the code or thread in default.aspx isn't stopped.

CODE

default.aspx
Session("test") = "ok"
Response.Redirect("home.aspx", false)

home.aspx
Label1.Text = "session var test = " & Session("test") 

However, if I open a connection to a database (ex. access) and close it (I'm not doing any query action on it in my testing code, just opening and closing it) then the session variable gets lost.

CODE

Imports System.Data.OleDb

default.aspx
dim objConnection As OleDbConnection = New OleDbConnection(MyConnectionString)
objConnection.Open()
objConnection.Close()
Session("test") = "ok"
Response.Redirect("home.aspx", false)

home.aspx
Label1.Text = "session var test = " & Session("test") 

I could work with cookies to store the info, but I can't seem to figure out why this session var isn't stored.
Even, in a different web application (created in VS2010, now using VS2012) I have almost the same code without any problems (application properties seem the same, web.config, ...).
All testing is done on my localmachine, using the webserver of VS2012

RE: session variable lost after database connection, even with response.redirect("....", false

I see no reason why that would happen. I would recreate both pages to test again. Are there any errors when you run it, like the connection is not made?

RE: session variable lost after database connection, even with response.redirect("....", false

(OP)
Nope, I created the project again, without success.
The connection is fine, no errors, ... I stripped all the code (even re created it) to the code above.
When I comment out the objConnection.Open() and .Close() it works without a problem.

RE: session variable lost after database connection, even with response.redirect("....", false

I was not able to reproduce your issue. I used the same except for the oledb connection,i used a sqlconnection.

I suspect you may have some setting in the web.config that may be causing it. Check sessionstate and cookiesLess = ???

RE: session variable lost after database connection, even with response.redirect("....", false

(OP)
jbenson, thx for the help.
I was sure I was able to reproduce the error in a new webapp. However, in a new project this test code seems to work. So I'll have to check the project again.
The web.config is default and does not contain anything concerning sessionsetate & cookieLess,...

I'm using cookies for the moment. I'll try to change the project/test tomorrow. Thanks anyway, at this moment I'm sure this code should work in normal circumstances

RE: session variable lost after database connection, even with response.redirect("....", false

OK, glad it is working, i couldn't see any reason it wouldn't unless the web.config was changed. Post back if you have any issues.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close