Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Application_Error not called for SqlException

Application_Error not called for SqlException

Scheduled Pinned Locked Moved ASP.NET
c++databasedebuggingcomtesting
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _Superman_
    wrote on last edited by
    #1

    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.

    _Microsoft MVP (Visual C++) (October 2009 - September 2013)

    Polymorphism in C

    S 1 Reply Last reply
    0
    • _ _Superman_

      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.

      _Microsoft MVP (Visual C++) (October 2009 - September 2013)

      Polymorphism in C

      S Offline
      S Offline
      Sandeep Mewara
      wrote on last edited by
      #2

      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

      _ 1 Reply Last reply
      0
      • S Sandeep Mewara

        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

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        My Application_Error contains 3 lines - Server.GetLastError, Server.Transfer and Server.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 with customError mode="Off" and customError 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 a try...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.

        _Microsoft MVP (Visual C++) (October 2009 - September 2013)

        Polymorphism in C

        S 1 Reply Last reply
        0
        • _ _Superman_

          My Application_Error contains 3 lines - Server.GetLastError, Server.Transfer and Server.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 with customError mode="Off" and customError 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 a try...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.

          _Microsoft MVP (Visual C++) (October 2009 - September 2013)

          Polymorphism in C

          S Offline
          S Offline
          Sandeep Mewara
          wrote on last edited by
          #4

          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

          _ 2 Replies Last reply
          0
          • S Sandeep Mewara

            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

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #5

            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 hit Application_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 a try...catch and re-throw the exception from the catch handler, it hits Application_Error. Anyway, thanks for your time. :)

            «_Superman_»  _I love work. It gives me something to do between weekends.

            _Microsoft MVP (Visual C++) (October 2009 - September 2013)

            Polymorphism in C

            1 Reply Last reply
            0
            • S Sandeep Mewara

              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

              _ Offline
              _ Offline
              _Superman_
              wrote on last edited by
              #6

              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.

              _Microsoft MVP (Visual C++) (October 2009 - September 2013)

              Polymorphism in C

              S 1 Reply Last reply
              0
              • _ _Superman_

                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.

                _Microsoft MVP (Visual C++) (October 2009 - September 2013)

                Polymorphism in C

                S Offline
                S Offline
                Sandeep Mewara
                wrote on last edited by
                #7

                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

                _ 1 Reply Last reply
                0
                • S Sandeep Mewara

                  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

                  _ Offline
                  _ Offline
                  _Superman_
                  wrote on last edited by
                  #8

                  Thanks Sandeep, It worked perfectly.

                  «_Superman_»  _I love work. It gives me something to do between weekends.

                  _Microsoft MVP (Visual C++) (October 2009 - September 2013)

                  Polymorphism in C

                  S 1 Reply Last reply
                  0
                  • _ _Superman_

                    Thanks Sandeep, It worked perfectly.

                    «_Superman_»  _I love work. It gives me something to do between weekends.

                    _Microsoft MVP (Visual C++) (October 2009 - September 2013)

                    Polymorphism in C

                    S Offline
                    S Offline
                    Sandeep Mewara
                    wrote on last edited by
                    #9

                    «_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

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups