Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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:
C#
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
C#
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
Updated 22-Feb-11 20:01pm
v2
Comments
Sandeep Mewara 23-Feb-11 2:01am    
Did you tried to look at the execution cycle using DEBUGGER? Where and how it's going?
TanzeelurRehman 23-Feb-11 2:48am    
First of All Thanks for your reply

Should i run the whole website through debugging.
TanzeelurRehman 23-Feb-11 3:15am    
Thankyou Sandeep Mewara, Basically there was error on DataAccess Layer, It got solved
Sandeep Mewara 23-Feb-11 4:01am    
:) Good to know.

1 solution

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.
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900