Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Session state lost after accessing database

Reply
Thread Tools

Session state lost after accessing database

 
 
William
Guest
Posts: n/a
 
      08-28-2004
Hi

I have an ASP.NET application that connects to an Access database.
Everything works fine except for the Session object. Data in the session
object is lost after I've made a call to the database.

To test, I've created two test aspx pages. Test1.aspx contains two buttons.
The first button sets values in the session object and then navigates to
Test2.aspx. Test2.aspx only displays the values in the session object.
The second button creates a connection to the database, executes a SQL
statement and then does exactly the same as the first button. (Code is
copied from first button). In Test2.aspx, the values set is seen as Nothing.

For the connection to the database, I tried:
- Created a custom data class that creates the connection and provides
access to the
database. Connection is a OledbConnection connecting via OLEDB JET.
- Used the same class but changed the connection to OdbcConnection.
- Created the connection directly from the aspx page.

The SQL statement executes with no problem, but as soon as the procedure /
function has finished executing, the session data is lost. I changed the
connection to test it on a SQL Server database. Works fine. However, the
server where the application is to be deployed does not have SQL Server and
we must use an Access database. I've done something similar in old ASP
before and it worked fine.

Any help, please.


 
Reply With Quote
 
 
 
 
Scott Allen
Guest
Posts: n/a
 
      08-28-2004
Hi William:

Are you doing a Response.Redirect after setting a session variable for
the first time?

Session["SomeValue"] = 42;
Response.Redirect("test2.aspx");

The first time you write to the session for a client ASP.NET creates a
cookie to send down to the browser. On following requests the browser
sends the cookie to the server and ASP.NET can find the user's
associated session. Unfortunately, Response.Redirect ends the request
early and the session cookie is lost.

One solution is to use:

Response.Redirect("test2.aspx", false);

The second parameter tells ASP.NET not to abort the request thread
early and the session survives.

HTH,

--
Scott
http://www.OdeToCode.com

On Sat, 28 Aug 2004 18:01:03 +0200, "William" <>
wrote:

>Hi
>
>I have an ASP.NET application that connects to an Access database.
>Everything works fine except for the Session object. Data in the session
>object is lost after I've made a call to the database.
>
>To test, I've created two test aspx pages. Test1.aspx contains two buttons.
>The first button sets values in the session object and then navigates to
>Test2.aspx. Test2.aspx only displays the values in the session object.
>The second button creates a connection to the database, executes a SQL
>statement and then does exactly the same as the first button. (Code is
>copied from first button). In Test2.aspx, the values set is seen as Nothing.
>
>For the connection to the database, I tried:
>- Created a custom data class that creates the connection and provides
>access to the
>database. Connection is a OledbConnection connecting via OLEDB JET.
>- Used the same class but changed the connection to OdbcConnection.
>- Created the connection directly from the aspx page.
>
>The SQL statement executes with no problem, but as soon as the procedure /
>function has finished executing, the session data is lost. I changed the
>connection to test it on a SQL Server database. Works fine. However, the
>server where the application is to be deployed does not have SQL Server and
>we must use an Access database. I've done something similar in old ASP
>before and it worked fine.
>
>Any help, please.
>


 
Reply With Quote
 
 
 
 
William
Guest
Posts: n/a
 
      08-28-2004
Hi

Actually I've been using Server.Transfer and also tried just a normal
hyperlink. I can even have the two buttons on the same webform. One button
updates values in the session state and executes a SQL statement while the
other just displays the session values in a label control and the session
values will still be lost.

Regards

William



"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:...
> Hi William:
>
> Are you doing a Response.Redirect after setting a session variable for
> the first time?
>
> Session["SomeValue"] = 42;
> Response.Redirect("test2.aspx");
>
> The first time you write to the session for a client ASP.NET creates a
> cookie to send down to the browser. On following requests the browser
> sends the cookie to the server and ASP.NET can find the user's
> associated session. Unfortunately, Response.Redirect ends the request
> early and the session cookie is lost.
>
> One solution is to use:
>
> Response.Redirect("test2.aspx", false);
>
> The second parameter tells ASP.NET not to abort the request thread
> early and the session survives.
>
> HTH,
>
> --
> Scott
> http://www.OdeToCode.com
>
> On Sat, 28 Aug 2004 18:01:03 +0200, "William" <>
> wrote:
>
> >Hi
> >
> >I have an ASP.NET application that connects to an Access database.
> >Everything works fine except for the Session object. Data in the session
> >object is lost after I've made a call to the database.
> >
> >To test, I've created two test aspx pages. Test1.aspx contains two

buttons.
> >The first button sets values in the session object and then navigates to
> >Test2.aspx. Test2.aspx only displays the values in the session object.
> >The second button creates a connection to the database, executes a SQL
> >statement and then does exactly the same as the first button. (Code is
> >copied from first button). In Test2.aspx, the values set is seen as

Nothing.
> >
> >For the connection to the database, I tried:
> >- Created a custom data class that creates the connection and provides
> >access to the
> >database. Connection is a OledbConnection connecting via OLEDB JET.
> >- Used the same class but changed the connection to OdbcConnection.
> >- Created the connection directly from the aspx page.
> >
> >The SQL statement executes with no problem, but as soon as the procedure

/
> >function has finished executing, the session data is lost. I changed the
> >connection to test it on a SQL Server database. Works fine. However, the
> >server where the application is to be deployed does not have SQL Server

and
> >we must use an Access database. I've done something similar in old ASP
> >before and it worked fine.
> >
> >Any help, please.
> >

>



 
Reply With Quote
 
[MSFT]
Guest
Posts: n/a
 
      08-30-2004
Hi William,

How did you set the session configration in web.config? Additionlly, if we
didn't redirect to Test2.aspx, just display the sessiob variant in same
page (Test1.aspx), like:

Response.Wrtie(var);

Will this work fine?

Luke

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET 2.0 Session State and ASP.NET 1.1 Session State jnickfl1 ASP .Net 0 09-18-2006 03:23 PM
Unable to make the session state request to the session state server Maciek ASP .Net 0 09-15-2005 08:49 PM
Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'. Mike Larkin ASP .Net 1 05-23-2005 12:33 PM
Unable to make the session state request to the session state server Not Liking Dot Net Today ASP .Net 0 04-21-2004 11:54 AM
unable to make the session state request to the session state server shamanthakamani ASP .Net 1 11-20-2003 04:51 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57