我有一个使用 VB.NET、SSRS 和 SQL Server 2008 R2 在 Visual Studio 2010 中开发的 ASP.NET 4.0 应用程序。应用程序中有一个页面收集来自用户的输入,它用作参数从 SQL Server 数据库中获取数据,并将其放入 SSRS 报告中,然后将其转换为 PDF 文件。这一切在我的开发机器上运行良好,但在服务器上特别是当它尝试对 ServerReport 引擎执行任何操作时出错。除了能够从我的开发机器上打开报告外,我还可以直接在报告管理器中打开它。当我尝试从生产机器打开报告时,报告没有打开,错误由页面左下角的黄色三角形指示,双击打开此消息。
`Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB7.4; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; CMDTDF; BRI/1; .NET4.0C; InfoPath.3; .NET4.0E)
Timestamp: Wed, 12 Dec 2012 20:03:54 UTC
Message: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500
ScriptResource.axd Line: 2
Code: 0 Char: 74741
URI: http://intranet/webapps/RecordedOnlyIncidents/ScriptResource.axd?d=GnweTchBv7S3iPh-J2y96yey3C3_pzddkEeS0GIM0GHz6A1wrAToLVysD0C0nmS_sugidnIpUa9dt3MXUvPZgTV3kdSrhNnjjikolQ4t_qbyruxeky4MDgxR-klgMjZP0&t=ffffffffbad362a4`
生产机器运行 Windows 2003 和 IIS 6 开发机器运行 Window 7 和 IIS 7 这两台机器都访问 SQL Server 和 Report Server,它们位于运行 Windows Server 2008 R2 Standard 的 VMware 虚拟服务器上。
我查看了运行应用程序的服务器上的事件日志,但没有找到任何关于实际错误的线索。我还查看了位于 C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\LogFiles 的报表服务器上的日志文件。当我在我的开发机器上运行应用程序时,报告会打开,并且将以下行添加到日志中,“library!ReportServer_0-30!1614!11/27/2012-20:18:54:: i INFO: RenderForNewSession(' /RecordedOnlyIncidents/Reports/AllIncidentsWithParameters')”。如果我随后更改开发机器上指定无效路径的代码,从而出现错误,则仍然有一个条目指定错误。“库!ReportServer_0-30!1674!11/27/2012-18:30:19::e 错误:抛出 Microsoft.ReportingServices.Diagnostics.Utilities。InvalidItemPathException: , Microsoft.ReportingServices.Diagnostics.Utilities.InvalidItemPathException: 项目 '/ReportViewer.aspx?/RecordedOnlyIncidents/Reports/AllIncidentsWithParameters' 的路径无效。完整路径的长度必须少于 260 个字符;其他限制适用。如果报表服务器处于本机模式,则路径必须以斜杠开头。;" 但是,如果我在服务器上运行应用程序并收到错误,则日志中没有条目,所以我假设甚至没有尝试访问报表服务器。
我的代码如下:
`Dim r = New ServerReport
r.ReportServerUrl = New Uri("http://vm-intranet/ReportServer")
r.ReportPath = "/RecordedOnlyIncidents/Reports/AllIncidentsWithParameters"
Dim EmployeeNumber As String = IIf(txtSearchEmployeeNumber.Text = "", Nothing, txtSearchEmployeeNumber.Text)
Dim IncidentType As String = IIf(ddlSearchIncidentType.SelectedItem.Text = "", Nothing, ddlSearchIncidentType.SelectedItem.Text)
Dim BeginningDate As String = IIf(txtBeginningDate.Text = "", Nothing, txtBeginningDate.Text)
Dim EndingDate As String = IIf(txtEndingDate.Text = "", Nothing, txtEndingDate.Text)
Dim parmEmpNumEmployeeNumber As New ReportParameter("EmployeeNumber", EmployeeNumber)
Dim parmIncidentType As New ReportParameter("IncidentType", IncidentType)
Dim parmBeginningDate As New ReportParameter("BeginningDate", BeginningDate)
Dim parmEndingDate As New ReportParameter("EndingDate", EndingDate)
Dim parameters(3) As ReportParameter
parameters(0) = parmEmpNumEmployeeNumber
parameters(1) = parmIncidentType
parameters(2) = parmBeginningDate
parameters(3) = parmEndingDate
r.SetParameters(parameters)
Dim warnings As Warning() = Nothing
Dim streamids As String() = Nothing
Dim mimeType As String = Nothing
Dim encoding As String = Nothing
Dim extension As String = Nothing
Dim reportOutput As Byte() = r.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)
Dim path As String = System.AppDomain.CurrentDomain.BaseDirectory
Dim stream As New IO.FileStream(path & "/MyReport.pdf", IO.FileMode.Create)
IO.FileMode.Create)
stream.Write(reportOutput, 0, reportOutput.Length)
stream.Close()
Dim Script As String = "<script type='text/javascript'> win=window.open("""",""_blank"",""resizable=Yes,height=600"");win=win.document;win.write(""<style>body{margin:0px;}</style>"");win.write(""<title> Incidents Report</title>"");win.write(""<iframe src='MyReport.pdf' style='width:100%;height:100%;'></iframe>"");</script>"
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "OpenReport", Script, False)`
错误发生在该行:
`r.SetParameters(parameters)`
但是,我也尝试过使用不带参数的报告,然后在线发生错误:
`Dim reportOutput As Byte() = r.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)`
任何建议将不胜感激。