Application_Error not called for SqlException
-
Application_Error exists in Global.asax. Most of the unhandled exception are caught here. While testing, I changed the name of a stored procedure to something that doesn't exist in the database. Now the control does not come to Application_Error. When I debug the app, the debugger shows exception when ExecuteReader is called. I do not have any try...catch I believe all exceptions must be caught by Application_Error. But it does not behave so.
«_Superman_» _I love work. It gives me something to do between weekends.
-
Application_Error exists in Global.asax. Most of the unhandled exception are caught here. While testing, I changed the name of a stored procedure to something that doesn't exist in the database. Now the control does not come to Application_Error. When I debug the app, the debugger shows exception when ExecuteReader is called. I do not have any try...catch I believe all exceptions must be caught by Application_Error. But it does not behave so.
«_Superman_» _I love work. It gives me something to do between weekends.
Can you share few information? 1. What code is present in your Application_Error? If you remove everything in it and place debugger, does it hit the method? 2. IIS7? CustomError mode in Web.config? 3. Are other methods of Global.asax getting triggered, like Session_start? 4. Is there any other .config file in your application?
Sandeep Mewara Microsoft ASP.NET MVP 2012 & 2013 [My Blog] [My Latest Post]: How to extend a WPF Textbox to Custom Picker
-
Can you share few information? 1. What code is present in your Application_Error? If you remove everything in it and place debugger, does it hit the method? 2. IIS7? CustomError mode in Web.config? 3. Are other methods of Global.asax getting triggered, like Session_start? 4. Is there any other .config file in your application?
Sandeep Mewara Microsoft ASP.NET MVP 2012 & 2013 [My Blog] [My Latest Post]: How to extend a WPF Textbox to Custom Picker
My
Application_Error
contains 3 lines -Server.GetLastError
,Server.Transfer
andServer.ClearError
. I tried removing all these lines and simply put a return statement on a breakpoint, but it did not hit. My development environment is IIS 5.1, Windows XP, Visual Studio 2010. I tried both withcustomError mode="Off"
andcustomError mode="On"
with the same results.Session_Start
is being called in Global.asax and I checked it by placing a breakpoint. I only have a web.config file. I created another sample file and tried it with the same results. I have shared the sample for you if you have the time. https://docs.google.com/file/d/0BwxeXZOAvlxJa3AxMUIxVkVUSEk/edit?usp=sharing[^] You can download it by selecting File -> Download. Since I'm not a web developer, my current solution is to place atry...catch
and then redirect to the error page from the catch handler. This works for me. Any help would be appreciated. Thanks for your time.«_Superman_» _I love work. It gives me something to do between weekends.
-
My
Application_Error
contains 3 lines -Server.GetLastError
,Server.Transfer
andServer.ClearError
. I tried removing all these lines and simply put a return statement on a breakpoint, but it did not hit. My development environment is IIS 5.1, Windows XP, Visual Studio 2010. I tried both withcustomError mode="Off"
andcustomError mode="On"
with the same results.Session_Start
is being called in Global.asax and I checked it by placing a breakpoint. I only have a web.config file. I created another sample file and tried it with the same results. I have shared the sample for you if you have the time. https://docs.google.com/file/d/0BwxeXZOAvlxJa3AxMUIxVkVUSEk/edit?usp=sharing[^] You can download it by selecting File -> Download. Since I'm not a web developer, my current solution is to place atry...catch
and then redirect to the error page from the catch handler. This works for me. Any help would be appreciated. Thanks for your time.«_Superman_» _I love work. It gives me something to do between weekends.
Hi Santosh, I downloaded it and opened in my VS2010 as a website. Set the break points in Global.sax. Built and ran. Guess what? It hit the Application_Error method. Am I missing something or you are? Please re-run the application that you shared with me with breakpoints and see again.
Sandeep Mewara Microsoft ASP.NET MVP 2012 & 2013 [My Blog] [My Latest Post]: How to extend a WPF Textbox to Custom Picker
-
Hi Santosh, I downloaded it and opened in my VS2010 as a website. Set the break points in Global.sax. Built and ran. Guess what? It hit the Application_Error method. Am I missing something or you are? Please re-run the application that you shared with me with breakpoints and see again.
Sandeep Mewara Microsoft ASP.NET MVP 2012 & 2013 [My Blog] [My Latest Post]: How to extend a WPF Textbox to Custom Picker
I'm definitely missing something. It still gave me the same behavior. So to make sure, I used Windows 8 and Visual Studio 2012. I created a new application and it still gave me the same behavior. It hit
Session_Start
, but did not hitApplication_Error
. While debugging the error is shown in Default.aspx.cs and it says SqlException was unhandled by user code and Could not find stored procedure 'StoredProcedure2'. If I use atry...catch
and re-throw the exception from thecatch
handler, it hitsApplication_Error
. Anyway, thanks for your time. :)«_Superman_» _I love work. It gives me something to do between weekends.
-
Hi Santosh, I downloaded it and opened in my VS2010 as a website. Set the break points in Global.sax. Built and ran. Guess what? It hit the Application_Error method. Am I missing something or you are? Please re-run the application that you shared with me with breakpoints and see again.
Sandeep Mewara Microsoft ASP.NET MVP 2012 & 2013 [My Blog] [My Latest Post]: How to extend a WPF Textbox to Custom Picker
I suspected some configuration issue here because the machines were used a lot before and so installed a fresh copy of Windows 8 and Visual Studio 2012. Now I'm able to get it to work. Thanks for your time. However, I have one question. Why is the debugger showing an exception in the .cs file before hitting
Application_Error
?Application_Error
is hit only when F5 is pressed again after the exception is shown. The exception can be see here - https://docs.google.com/file/d/0BwxeXZOAvlxJc28teld2R1BkVEk/edit?usp=sharing[^]«_Superman_» _I love work. It gives me something to do between weekends.
-
I suspected some configuration issue here because the machines were used a lot before and so installed a fresh copy of Windows 8 and Visual Studio 2012. Now I'm able to get it to work. Thanks for your time. However, I have one question. Why is the debugger showing an exception in the .cs file before hitting
Application_Error
?Application_Error
is hit only when F5 is pressed again after the exception is shown. The exception can be see here - https://docs.google.com/file/d/0BwxeXZOAvlxJc28teld2R1BkVEk/edit?usp=sharing[^]«_Superman_» _I love work. It gives me something to do between weekends.
Now, since you share further steps, try to disable all code exceptions in VS: Do Cntrl+Alt+E in Visual Studio and then uncheck all - Application_Error should get hit. I guess it does not work otherwise. Worth a shot?
Sandeep Mewara Microsoft ASP.NET MVP 2012 & 2013 [My Blog] [My Latest Post]: How to extend a WPF Textbox to Custom Picker
-
Now, since you share further steps, try to disable all code exceptions in VS: Do Cntrl+Alt+E in Visual Studio and then uncheck all - Application_Error should get hit. I guess it does not work otherwise. Worth a shot?
Sandeep Mewara Microsoft ASP.NET MVP 2012 & 2013 [My Blog] [My Latest Post]: How to extend a WPF Textbox to Custom Picker
Thanks Sandeep, It worked perfectly.
«_Superman_» _I love work. It gives me something to do between weekends.
-
Thanks Sandeep, It worked perfectly.
«_Superman_» _I love work. It gives me something to do between weekends.
«_Superman_» wrote:
It worked perfectly.
Awesome! Glad I could help you out. :)
Sandeep Mewara Microsoft ASP.NET MVP 2012 & 2013 [My Blog]: Sandeep Mewara's Tech Journal! [My Latest Article]: HTML5 Quick Start Web Application