Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
Hi EveryOne
 
I am working on a project, where I have to handle error handling globally using Global.asax function
"void Application_Error(object sender, EventArgs e) "
My code in the Global.asax file is like this:
void Application_Error(object sender, EventArgs e)
   {
       // Code that runs when an unhandled error occurs
       DBUtill dbobj = new DBUtill(); // This is my class for all sorts of
                                      // functionality for my project
       dbobj.App_Error();  // This is my function where i am saving the error
                           // To a database.
   }
From one of my pages in the load event i am throwing unhandled exception just to check whether it is working or not. like below
   throw (new ArgumentNullException());
 
For the purpose of easiness i am including my App_Error function also
public void App_Error()
   {
 
       Exception ex = HttpContext.Current.Server.GetLastError().GetBaseException();
 
       string sql = string.Format("insert into tbl_ApplicationErrors (ErrorType,ErrorPage,ErrorDetail) values ('{0}','{2}','{2}')", ex.Source.Replace("'", ""), HttpContext.Current.Request.Url.ToString().Replace("'", ""), ex.ToString().Replace("'", ""));
       ScalarSql(sql);
       HttpContext.Current.Server.ClearError();
       HttpContext.Current.Response.Redirect("~/Error.aspx");
   }
 
By the first and second time it went right and also inserted values in the database, I mean the Application_Error function fired by the first and second time, but onward it is not working.
 
What should be the problem, each and every solution will be appreciated.
Posted 22-Feb-11 19:02pm
Edited 22-Feb-11 20:01pm
v2
Comments
Sandeep Mewara at 23-Feb-11 2:01am
   
Did you tried to look at the execution cycle using DEBUGGER? Where and how it's going?
TanzeelurRehman at 23-Feb-11 2:48am
   
First of All Thanks for your reply
 
Should i run the whole website through debugging.
TanzeelurRehman at 23-Feb-11 3:15am
   
Thankyou Sandeep Mewara, Basically there was error on DataAccess Layer, It got solved
Sandeep Mewara at 23-Feb-11 4:01am
   
:) Good to know.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Answering it to remove from Unanswered list.
 
OP resolved the same by himself. There was an issue at DataAccess layer which got resolved on DEBUGGING.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 216
1 CPallini 195
2 BillWoodruff 180
3 Maciej Los 165
4 Kornfeld Eliyahu Peter 140


Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 23 Feb 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100