473,606 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Session state lost after accessing database

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.
Nov 18 '05 #1
3 2598
Hi William:

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

Session["SomeValue"] = 42;
Response.Redire ct("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.Redire ct ends the request
early and the session cookie is lost.

One solution is to use:

Response.Redire ct("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" <Vi***@online.n ospam>
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.


Nov 18 '05 #2
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:5s******** *************** *********@4ax.c om...
Hi William:

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

Session["SomeValue"] = 42;
Response.Redire ct("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.Redire ct ends the request
early and the session cookie is lost.

One solution is to use:

Response.Redire ct("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" <Vi***@online.n ospam>
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 andwe must use an Access database. I've done something similar in old ASP
before and it worked fine.

Any help, please.

Nov 18 '05 #3
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

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2673
by: Matt | last post by:
I have several applications running in a hosted environment and the provider will not allow either a session state service or a session state on the sql server. Is there any way I can add the session state tables to my own database and use that instead? I have tried to put the "initial catalog" in the connect string, but .Net doesn't like that... Matt... mtatro@lgc.com
0
1002
by: Artie | last post by:
I have a web site that uses session variable to carry user information around once they have logged into the site. At random times the session.id will change to a new id or even worse, to a different users session.id. I have a static frame that I have written the session.id into a hidden field, and then verify it on each new page load in the main frame. It usually happens when there are several people on the site. Any ideas?
1
12853
by: Brian Schloz | last post by:
Hello, I just thought I'd share my particular situation regarding session state periodically being "lost" in my asp.net app. I read with interest all of the posts regarding lost session state (virus scanner, modified assemblies/configs, etc.). The suggested solution of using a 'State Server' or 'SQL State Server' was not attractive to me given the drawbacks: performance, objects must be serializable, no more Session_End.
0
951
by: Jeff | last post by:
Hi I have an asp.net application that opens a new browser window on clicking a hyperlink. I pass Session information across (using the APSnet user at runtime) sucessfully in the development environment. When deployed, the session info is lost and the IsNewSession variable is now true, i.e. a new SessionID. I'm guessing this is a IIS setting but can't find the answer. The Session info in the web config file is the same on
2
1146
by: Scott Vercuski | last post by:
Hello all, I've got a question about session state. Is it possible to declare and load a session into a session object from the sql server database. Here's the scenario ... I've got a website using SqlServer as the session state manager. I've got a web service that I'd like to pass in the SessionID and have it load the session from the database. I'd just like to know if this is possible.
4
1132
by: SteveSu | last post by:
Hi! I have a few question regarding sql session state. Is the database hited only ones when the session is created and then no database hit until session expires or is there a database hit every time a new page is rendered like when using profiles? If the database is only hitted when creating the session then how is the data saved while the session is "living"? I want to use sql state cause´ my site will be hosted by a webfarm with...
2
2109
by: Ivers | last post by:
My C# asp.net app (.NET 1.1) can generate an email whose body contains a link to the current page of the app. When the recipient of the email clicks the link (usually from Outlook), the app launches just fine, and will postback great too. However, when the user pastes this link into a PowerPoint 2003 hyperlink, runs the slideshow, and clicks on the link, it brings up the right page, but generates the error "Object reference not set to...
0
2083
by: Tim Greenwood | last post by:
We just discovered that the "temp' database ASPState is in full recovery mode. Is this necessary? Seems ridiculously overkill seeing that when we reboot the sql server machine we really don't need asp state to remain persistent. Also causes our tlog to be unnecessarily large..... Is it safe to change this to Simple ???? Thanks for any input.....inquiring minds are waiting for me to answer :)
5
2452
by: spoonybard | last post by:
Hi Everyone, We have a C# ASP.Net 2.0 web application that is running on 2 load balancing servers. Using Internet Explorer 6.0/7.0, Firefox, Safari, etc... there are no problems with the sessions. However, using AOL, the sessions get dropped because of the proxy servers AOL uses. Can anyone point us in the right direction on how to maintain the session state by possibly using GUID's or some other method. Thanks.
0
8045
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8467
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8462
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8127
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8320
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4011
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2458
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1574
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1315
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.