We have a couple of web applications that make use of the web ReportViewer control to connect and pull report data from Reporting Services. An odd behavior we observe in the UAT environment – does not happen in our workstations or staging servers – is the ReportViewer will throw an error the first time it is being used by the web applications. The second and subsequent requests would then work properly as expected.
System.InvalidOperationException: Client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'. The request failed with the error message: --
Server Error in '/ReportServer' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Microsoft.ReportingServices.Diagnostics.Dumper.DumpHere(Exception optionalException, String assertionMessage) +143
Microsoft.ReportingServices.Diagnostics.Utilities.RSException..ctor(ErrorCode errorCode, String localizedMessage, Exception innerException, RSTrace tracer, String additionalTraceMessage) +369
Microsoft.ReportingServices.Diagnostics.Utilities.ReportCatalogException..ctor(ErrorCode errorCode, String localizedMessage, Exception innerException, String additionalTraceMessage) +46
Microsoft.ReportingServices.Diagnostics.Utilities.InternalCatalogException..ctor(Exception innerException, String additionalTraceMessage) +47
Microsoft.ReportingServices.WebServer.ReportServiceHttpHandler.WriteErrorResponse(Int32 code, String shortHttpDescription, Exception exception, Boolean errorResponseAsXml) +73
Microsoft.ReportingServices.WebServer.Global.WriteServerError(Exception e) +44
Microsoft.ReportingServices.WebServer.Global.Application_BeginRequest(Object sender, EventArgs e) +245
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42 --. at Microsoft.SqlServer.ReportingServices2005.Execution.RSExecutionConnection.GetSecureMethods() at Microsoft.SqlServer.ReportingServices2005.Execution.RSExecutionConnection.IsSecureMethod(String methodname) at Microsoft.SqlServer.ReportingServices2005.Execution.RSExecutionConnection.LoadReport(String Report, String HistoryID) at Microsoft.Reporting.WebForms.ServerReport.GetExecutionInfo() at Microsoft.Reporting.WebForms.ServerReport.SetParameters(IEnumerable`1 parameters) at Reports_Report_Generate.btnGenerate_Click(Object sender, EventArgs e)
The nature of the top error shows the SSRS web service returning HTML output upon hitting an error, which is announced in the lower stack trace. What we’ve discovered is on first request, the ReportViewer is somehow passing in anonymous credentials to SSRS, instead of using the AppPool identity which has permission to access the reports. The Reporting services log file shows an access-denied error for the first request.
w3wp!library!1!11/9/2007-09:01:18:: i INFO: Initializing WatsonDumpExcludeIfContainsExceptions to 'System.Data.SqlClient.SqlException,System.Threading.ThreadAbortException' as specified in Configuration file.
w3wp!library!1!11/9/2007-09:01:18:: i INFO: Initializing SecureConnectionLevel to '0' as specified in Configuration file.
w3wp!library!1!11/9/2007-09:01:18:: i INFO: Initializing DisplayErrorLink to 'True' as specified in Configuration file.
w3wp!library!1!11/9/2007-09:01:18:: i INFO: Initializing WebServiceUseFileShareStorage to 'False' as specified in Configuration file.
w3wp!library!1!11/9/2007-09:01:18:: e ERROR: Throwing Microsoft.ReportingServices.Diagnostics.Utilities.InternalCatalogException: An internal error occurred on the report server. See the error log for more details., ;
Info: Microsoft.ReportingServices.Diagnostics.Utilities.InternalCatalogException: An internal error occurred on the report server. See the error log for more details. ---> System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Also noted is the first request is significantly slow, usually taking half a minute before it initializes to display ReportViewer control in “loading” mode on the browser. Again, it is slow but works properly on our machines while somehow the UAT server has that extra problem above. Initially we thought we had overcome the issue by using an explicit IReportServerCredentials object that returns the process identity for use with the report request. It appeared to fix the problem when I redeployed the web application, but the problem has returned again.
ReportViewer dynamicViewer = new ReportViewer();
dynamicViewer.Width = new Unit("100%");
pageViewReport.Controls.Add(dynamicViewer);
dynamicViewer.Enabled = true;
//this.dynamicViewer.Reset();
dynamicViewer.ProcessingMode = ProcessingMode.Remote;
dynamicViewer.ServerReport.ReportServerCredentials = new ReportServerCredentials();
dynamicViewer.ServerReport.ReportServerUrl = new Uri(reportServerUrl);
dynamicViewer.ServerReport.ReportPath = reportPath + reportInfo.ReportName;
dynamicViewer.ServerReport.SetParameters(parameters);
dynamicViewer.ServerReport.Refresh();
Has anybody witnessed such behavior before?
The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral