Environment: ASP.NET 2.0, SQL Server 2005, C#, Visual Studio 2005
In my Session_End event, I am executing a stored procedure to update a
database table that is used to log user sessions.
When the user sessions time out, the Session_End event fires successfully.
The stored procedure executes successfully, and I can see the updated data in
the database just as I would expect.
Nonetheless, an exception is being generated by the code that I'ved added to
the Session_End event. This is what part of the exception looks like when
it's emailed to me from the ASP.NET Health Monitoring service:
======
Exception information:
Exception type: System.NullRefe renceException
Exception message: Object reference not set to an instance of an object.
Thread information:
Thread ID: 1
Thread account name: NT AUTHORITY\NETWO RK SERVICE
Is impersonating: False
Stack trace: at ASP.global_asax .Session_End(Ob ject sender, EventArgs e)
=====
And here is the code that of my Session_End event handler:
=====
void Session_End(obj ect sender, EventArgs e)
{
try
{
SqlConnection con = new
SqlConnection(C onfigurationMan ager.Connection Strings["db"].ConnectionStri ng);
SqlCommand cmd = new
SqlCommand("Fin alizeAuthentica tedUserSession" , con);
cmd.CommandType = System.Data.Com mandType.Stored Procedure;
// Add the parameters
// The LogID for this log entry is stored in the session variable
cmd.Parameters. Add(new SqlParameter("@ LogID", SqlDbType.Int, 4));
cmd.Parameters["@LogID"].Value = (int)Session["LogID"];
// @SessionEndDate Time is expressed in UTC
cmd.Parameters. Add(new SqlParameter("@ SessionEndDateT ime",
SqlDbType.DateT ime, 8));
cmd.Parameters["@SessionEndDat eTime"].Value = DateTime.UtcNow ;
try
{
con.Open();
cmd.ExecuteNonQ uery();
}
catch (SqlException err)
{
throw new ApplicationExce ption("A database exception
occurred while updating the authenticated user's record in the database in
the Session_End event handler: " + err.Message);
}
finally
{
con.Close();
}
}
catch (Exception err)
{
throw new ApplicationExce ption("An exception occurred in the
Session_End event handler: " + err.Message);
}
}
=====
Even though the database is being updated correctly, I'm overwhelmed with
error messages from the Health Monitoring service.
If I had to venture a guess, I'd say that one of the resources that is being
cleaned up after the execution of the stored procedure cannot be cleaned up,
due to the session ending.
Yes, I've tried debugging this, and I have not been successful in stepping
through an execution of the code that led to the exception.
Any assistance anyone could provide here would be welcome.
-- brent 1 6937
you are not validating that the session data (LogId) exists before using it.
-- bruce (sqlwork.com)
brent960 wrote:
Environment: ASP.NET 2.0, SQL Server 2005, C#, Visual Studio 2005
In my Session_End event, I am executing a stored procedure to update a
database table that is used to log user sessions.
When the user sessions time out, the Session_End event fires successfully.
The stored procedure executes successfully, and I can see the updated data in
the database just as I would expect.
Nonetheless, an exception is being generated by the code that I'ved added to
the Session_End event. This is what part of the exception looks like when
it's emailed to me from the ASP.NET Health Monitoring service:
======
Exception information:
Exception type: System.NullRefe renceException
Exception message: Object reference not set to an instance of an object.
Thread information:
Thread ID: 1
Thread account name: NT AUTHORITY\NETWO RK SERVICE
Is impersonating: False
Stack trace: at ASP.global_asax .Session_End(Ob ject sender, EventArgs e)
=====
And here is the code that of my Session_End event handler:
=====
void Session_End(obj ect sender, EventArgs e)
{
try
{
SqlConnection con = new
SqlConnection(C onfigurationMan ager.Connection Strings["db"].ConnectionStri ng);
SqlCommand cmd = new
SqlCommand("Fin alizeAuthentica tedUserSession" , con);
cmd.CommandType = System.Data.Com mandType.Stored Procedure;
// Add the parameters
// The LogID for this log entry is stored in the session variable
cmd.Parameters. Add(new SqlParameter("@ LogID", SqlDbType.Int, 4));
cmd.Parameters["@LogID"].Value = (int)Session["LogID"];
// @SessionEndDate Time is expressed in UTC
cmd.Parameters. Add(new SqlParameter("@ SessionEndDateT ime",
SqlDbType.DateT ime, 8));
cmd.Parameters["@SessionEndDat eTime"].Value = DateTime.UtcNow ;
try
{
con.Open();
cmd.ExecuteNonQ uery();
}
catch (SqlException err)
{
throw new ApplicationExce ption("A database exception
occurred while updating the authenticated user's record in the database in
the Session_End event handler: " + err.Message);
}
finally
{
con.Close();
}
}
catch (Exception err)
{
throw new ApplicationExce ption("An exception occurred in the
Session_End event handler: " + err.Message);
}
}
=====
Even though the database is being updated correctly, I'm overwhelmed with
error messages from the Health Monitoring service.
If I had to venture a guess, I'd say that one of the resources that is being
cleaned up after the execution of the stored procedure cannot be cleaned up,
due to the session ending.
Yes, I've tried debugging this, and I have not been successful in stepping
through an execution of the code that led to the exception.
Any assistance anyone could provide here would be welcome.
-- brent This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kenn Ghannon |
last post by:
I've got an ASP.NET page with a counter subtraction routine in the
Session_End method in the Global.asax.cs:
protected void Session_End(Object sender, EventArgs e)
{
ulong curUsers;
Application.Lock();
|
by: Steve M |
last post by:
Why are my sessions lasting so long?
I have them set to 20 minute timeout in config file?
The Session_End event is getting called an hour or more sometimes--well
after the user has stopped interacting with my site.
Anyone have any insight?
Thanks in advance
|
by: Savin Igor |
last post by:
What can be done in Session_End()?
Can I get something from Session in this handler?
My Global.asax.cs is below
using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
|
by: Beren |
last post by:
Hey,
I've got some code in my Session_End which cleans up all Session related
items from the Cache object.
I needed to store some related sessiondata in there to be able to address it
in the AuthenticateRequest event.
Now when I breakpoint the first line to test the Session_End code, it only
breaks on the first line.
A press on F11 through will just jump me out and resumes the program,
|
by: Timo |
last post by:
A few questions relating to sessions ending.
1. What happens to the session when a user closes the browser? Does the
session remain alive until it times out?
2. In the Session_End eventhandler, is it possible to distinguish between a
timeout and an explicit call to Session.Abandon (e.g. from a logout page)
without setting a session variable in the code that invokes Session.Abandon?
3. In the Session_End event, what is the
| |
by: OldProgrammer |
last post by:
All the documentation and discussion I have read indicate that the
Session_End is not supposed to fire unless you are in "inProc" Session state
mode, and then only on Session Timeout or at Session Abandon. I need the
event to fire at Session timeout in order to capture and store the Datetime
this occurs. However in the application I am writing, I have been unable
discern any indication that the event is firing. I have used break...
|
by: Roger |
last post by:
When I call the session.abandon() method, it calls the session_end event.
When a user closes the browser or clicks the log off button, I can dispose
of objects and abandon the session cleaning. But, when a user either
navigates away from the web app and when the session timesout, the
session_end event does not seem to fire. Or when else can I dispose of
objects? Or is there an event I can you that is fired when a user navigates
away from...
|
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= |
last post by:
Hi. I am trying to maintain a list of people who are currently "online" in
SQL. I do this by adding a simple entry to a simple PeopleOnline table
whenever someone logs in to my site.
If they manually log OUT of the site, I have no problem deleting them from
the PeopleOnline table. But if they just close the browser, I was assuming
I'd have to use the Session_End() event in Global.asax even though I know
that this will only occur once the...
|
by: anithaapr05 |
last post by:
After the session end i try to write the session value.In this, it write the session value after the session end, but i got the warning in application event.
My asp code:
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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...
|
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,...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| | |