x

Report Manager: ASP.NET Error Notifications

Can I get Report Manager (2005) to email me details of any ASP.NET exceptions/errors? I have seen suggestions for modifying the Global.asax file for ASP.NET projects but none of these seem to work for me and was hoping someone here had implemented a SQL Server specific solution!
more ▼

asked Aug 26, 2011 at 05:17 AM in Default

TomG gravatar image

TomG
11 1 1 1

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

If the error is logged in the ReportServer database then you could create a SQL Agent job to run every few minute and check for the error and then email you results if found.

I would suggest that you create a way of checking when the last check was executed so that you dont scan the whole database every time the job runs.

I am not sure how you would identify the error you want in particular though. I just ran

USE [ReportServer]
go

SELECT DISTINCT
    [el].[Status]
FROM    [dbo].[ExecutionLog] AS el
and only found a Status that indicated a failure of 'rsInternalError', there may be others that I don't have on this server though.
more ▼

answered Aug 26, 2011 at 05:43 AM

Fatherjack gravatar image

Fatherjack ♦♦
42.7k 75 79 108

Because it's at the Web Application level it doesn't end up in the ReportServer database. It's things like the Excel rendering failing. The report shows up as rsSuccess or somesuch in dbo.ReportServer but the user sees an ASP.NET error page with stack trace.
Aug 26, 2011 at 06:54 AM TomG
then I guess, as you are 2005, the web server log files may offer something. Have you looked in IIS?
Aug 26, 2011 at 07:39 AM Fatherjack ♦♦
I can check log files and even event logger on Server has some info but I was really hoping for some sort of email notification which includes the stack trace etc. I know this is generally possible with ASP.NET applications but it's beyond my know-how to get it working in Report Manager. Thank you for taking the time to answer.
Aug 26, 2011 at 07:55 AM TomG
If you know its possible then I'd suggest tracking down some ASP forum to find out how others have achieved it. I can see a way of doing it with importing the data from the log files and then running a report on the data but I fear it wouldnt be as elegant as a .Net solution. Good luck
Aug 26, 2011 at 07:59 AM Fatherjack ♦♦
(comments are locked)
10|1200 characters needed characters left

In the Global.asax, there is an Application_Error event which gets triggered whenever an unhandled exception bubbles up to the top without being caught by any other functions (so, on a website, that'd be a case where you get the yellow error page). If the code is trapping exceptions at a lower level and displaying text (which good code should be doing), you can't really use that event to capture an error.

For our developers' code, we log the exceptions in a database and fire off e-mails. In their code, they do this in try-catch blocks, but there's a catch-all Application_Error that looks a little bit like:

protected void Application_Error(object sender, EventArgs e)
        {
            ExceptionChit chit = null;
            Boolean UrlNotFoundException = false;
            Exception ex = HttpContext.Current.Server.GetLastError().GetBaseException();
            try
            {
                if (ex is HttpException)
                {
                    HttpException hex = (HttpException)ex;
                    if (hex.GetHttpCode() == 404) UrlNotFoundException = true;
                }
                if (!UrlNotFoundException)
                {
                    //This logs the exception and sends out the relevant e-mail.
                    chit = ExceptionChit.LogException(ex, Request, "Application", "Username");
                }
                Server.ClearError();
            }
            finally
            {
                if (UrlNotFoundException)
                {
                    Response.Redirect("~/Default.aspx");
                }
                else
                {
                   //Do some other stuff that I've taken out from here.
                }
            }
        }

The exception chit code saves a record in a table, and then you could have a SQL Agent job run every few minutes or so to send out e-mails. ex (the exception) contains properties like Message and StackTrace, so you could put them directly into the table. The stack trace can get pretty long, though, so you may want to think about maintenance with that table if you have a lot of exceptions.

I believe you would need to be able to re-compile the code before Global.asax changes take effect. I haven't messed with the Report Manager code, so I don't even know if you can compile it yourself.
more ▼

answered Aug 26, 2011 at 08:18 AM

Kevin Feasel gravatar image

Kevin Feasel
6.1k 3 5 11

Kevin - wouldn't a simple stop//start of the reporting services website cause it to recompile?
Aug 26, 2011 at 08:24 AM Fatherjack ♦♦

Whenever you change the global.asax file, the site recompiles. No restart required.

Here is an overview of dynamic compilation - http://msdn.microsoft.com/en-us/library/ms366723(v=vs.90).aspx
Aug 26, 2011 at 08:34 AM KenJ
I've always re-built and re-deployed web application projects, so to be honest, I didn't even know that you could change the Global.asax on the fly like that.
Aug 26, 2011 at 01:12 PM Kevin Feasel
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x29
x27
x21

asked: Aug 26, 2011 at 05:17 AM

Seen: 1864 times

Last Updated: Aug 26, 2011 at 05:17 AM