2014-09-22 129 views
0

我嘗試將參數傳遞給我的報告時發生錯誤。將參數傳遞給報告c#

Microsoft.ReportViewer.WebForms.dll中發生未處理的「Microsoft.Reporting.WebForms.LocalProcessingException」類型異常。

我的代碼:

ReportViewer reportViwer = new ReportViewer(); 
reportViwer.ProcessingMode = ProcessingMode.Local; 

reportViwer.LocalReport.ReportEmbeddedResource = "MyReport.Report1.rdlc"; 

List<ReportParameter> listReportParameter = new List<ReportParameter>(); 

listReportParameter.Add(new ReportParameter("Name", "Test")); 

reportViwer.LocalReport.SetParameters(listReportParameter); 

的錯誤是在 「SetParameters」。

的描述:

Microsoft.Reporting.WebForms.LocalProcessingException was unhandled 
    HResult=-2146233088 
    Message=An error occurred during local report processing. 
    Source=Microsoft.ReportViewer.WebForms 
    StackTrace: 
     at Microsoft.Reporting.WebForms.LocalReport.CompileReport() 
     at Microsoft.Reporting.WebForms.LocalReport.SetParameters(IEnumerable`1 parameters) 
     at MyReport.Form1.button1_Click(Object sender, EventArgs e) in e:\_Organizado\AERON\Projetos\Visual Studio C#\Relatorio\MyReport\Form1.cs:line 37 
     at System.Windows.Forms.Control.OnClick(EventArgs e) 
     at System.Windows.Forms.Button.OnClick(EventArgs e) 
     at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) 
     at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 
     at System.Windows.Forms.Control.WndProc(Message& m) 
     at System.Windows.Forms.ButtonBase.WndProc(Message& m) 
     at System.Windows.Forms.Button.WndProc(Message& m) 
     at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
     at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
     at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 
     at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 
     at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) 
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) 
     at System.Windows.Forms.Application.Run(Form mainForm) 
     at MyReport.Program.Main() in e:\_Organizado\AERON\Projetos\Visual Studio C#\Relatorio\MyReport\Program.cs:line 19 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: Microsoft.Reporting.DefinitionInvalidException 
     HResult=-2146233088 
     Message=The definition of the report 'Main Report' is invalid. 
     Source=Microsoft.ReportViewer.Common 
     ExceptionLevelHelpLink=http://go.microsoft.com/fwlink/?LinkId=20476&EvtSrc=Microsoft.ReportingServices.Diagnostics.Utilities.ErrorStrings&EvtID=pvInvalidDefinition&ProdName=Microsoft%20SQL%20Server%20Reporting%20Services&ProdVer=9.0.21022.8 
     SkipTopLevelMessage=false 
     StackTrace: 
      at Microsoft.Reporting.ReportCompiler.CompileReport(CatalogItemContext context, Byte[] reportDefinition, Boolean generateExpressionHostWithRefusedPermissions, ReportSnapshotBase& snapshot) 
      at Microsoft.Reporting.StandalonePreviewStore.StoredReport.CompileReport() 
      at Microsoft.Reporting.StandalonePreviewStore.StoredReport.get_Snapshot() 
      at Microsoft.Reporting.StandalonePreviewStore.GetCompiledReport(CatalogItemContext context, Boolean rebuild, ReportSnapshotBase& snapshot) 
      at Microsoft.Reporting.LocalService.CompileReport(CatalogItemContext itemContext, Boolean rebuild) 
      at Microsoft.Reporting.WebForms.LocalReport.CompileReport() 
     InnerException: Microsoft.ReportingServices.ReportProcessing.ReportProcessingException 
      HResult=-2146233088 
      Message=The report definition is not valid. Details: The report definition has an invalid target namespace 'http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition' which cannot be upgraded. 
      Source=Microsoft.ReportViewer.Common 
      ExceptionLevelHelpLink=http://go.microsoft.com/fwlink/?LinkId=20476&EvtSrc=Microsoft.ReportingServices.Diagnostics.Utilities.ErrorStrings&EvtID=rsProcessingError&ProdName=Microsoft%20SQL%20Server%20Reporting%20Services&ProdVer=9.0.21022.8 
      SkipTopLevelMessage=false 
      StackTrace: 
       at Microsoft.ReportingServices.ReportProcessing.ReportPublishing.Phase1(CatalogItemContext reportContext, Byte[] definition, CreateReportChunk createChunkCallback, CheckSharedDataSource checkDataSourceCallback, String& description, String& language, DataSourceInfoCollection& dataSources, UserLocationFlags& userReferenceLocation, Boolean& hasExternalImages, Boolean& hasHyperlinks) 
       at Microsoft.ReportingServices.ReportProcessing.ReportPublishing.CreateIntermediateFormat(CatalogItemContext reportContext, Byte[] definition, CreateReportChunk createChunkCallback, CheckSharedDataSource checkDataSourceCallback, PublishingErrorContext errorContext, AppDomain compilationTempAppDomain, Boolean generateExpressionHostWithRefusedPermissions, String& description, String& language, ParameterInfoCollection& parameters, DataSourceInfoCollection& dataSources, UserLocationFlags& userReferenceLocation, ArrayList& dataSetsName, Boolean& hasExternalImages, Boolean& hasHyperlinks) 
       at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.CompileReport(CatalogItemContext reportContext, Byte[] reportDefinition, CreateReportChunk createChunkCallback, CheckSharedDataSource checkDataSourceCallback, PublishingErrorContext errorContext, AppDomain compilationTempAppDomain, Boolean generateExpressionHostWithRefusedPermissions, String& reportDescription, String& reportLanguage, ParameterInfoCollection& parameters, DataSourceInfoCollection& dataSources, UserLocationFlags& userReferenceLocation, ArrayList& dataSetsName, Boolean& hasExternalImages, Boolean& hasHyperlinks) 
       at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.CreateIntermediateFormat(CatalogItemContext reportContext, Byte[] reportDefinition, CreateReportChunk createChunkCallback, CheckSharedDataSource checkDataSourceCallback, AppDomain compilationTempAppDomain, Boolean generateExpressionHostWithRefusedPermissions) 
       at Microsoft.Reporting.ReportCompiler.CompileReport(CatalogItemContext context, Byte[] reportDefinition, Boolean generateExpressionHostWithRefusedPermissions, ReportSnapshotBase& snapshot) 
      InnerException: 

任何幫助感激!!

+2

看到這個[線程](http://social.msdn.microsoft.com/Forums/en-US/47ecd315-6372-46cf-b319-df098334fc74/the-report-definition-has-一個無效目標命名空間forum = vsreportcontrols),希望它有幫助 – qqbenq 2014-09-22 14:03:25

+0

我使用的是Visual 2013,而我的文件的頂部是: 2014-09-22 16:17:54

回答

0

在報告中添加名稱爲「名稱」和「測試」的參數,然後重試。

如果它已經完成,請嘗試更改

this.reportViewer1.LocalReport.ReportEmbeddedResource = "MyReport.Report1.rdlc"; 

要:

this.reportViewer1.LocalReport.ReportPath = "MyReport.Report1.rdlc"; 

你也可以試試這個:Uncheck 「名稱」 參數的Internal財產。

檢查報告中參數的屬性。 (右鍵單擊報告窗格中,選擇參數。)

UNCHECK - internal -

+0

我已經有了這個參數,沒有工作。 – 2014-09-22 16:20:00

1

感謝與我解決了這個問題的技巧。

當我加入referrence 「Microsoft.ReportViewer.WebForms.dll」 在Visual Studio得到的dll文件夾中:

C:\ Program Files文件(x86)的\微軟的Visual Studio 9.0 \的ReportViewer \微軟。 ReportViewer.WebForms.dll

我刪除了參考,並再次添加使用瀏覽器菜單中選擇文件夾中的DLL

C:\ Program Files文件(x86)的\微軟的Visual Studio 12.0 \的ReportViewer \ Microsoft.ReportViewer .WebForms.dll

但現在的問題是下一行:

Warning[] warnings; 
string[] streamids; 
string mineType = ""; 
string encoding = ""; 
string extension = ""; 

byte[] bytePDF = reportViewer.LocalReport.Render("Pdf", null , out mineType, out encoding, out extension, out streamids, out warnings); 

錯誤:

異常:拋出該異常:「運行報表所需的一個或多個參數還沒有被指定。」 (Microsoft.ReportingServices.ReportProcessing.ReportProcessingException) 引發了Microsoft.ReportingServices.ReportProcessing.ReportProcessingException:「運行報告所需的一個或多個參數尚未指定。」 時間:22/09/2014 14點59分58秒 主題:[4236]

Microsoft.Reporting.WebForms.LocalProcessingException was unhandled 
    HResult=-2146233088 
    Message=An error occurred during local report processing. 
    Source=Microsoft.ReportViewer.WebForms 
    StackTrace: 
     at Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings) 
     at Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings) 
     at Microsoft.Reporting.WebForms.LocalReport.Render(String format, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings) 
     at Microsoft.Reporting.WebForms.Report.Render(String format, String deviceInfo, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings) 
     at MyReport.Form1.button1_Click(Object sender, EventArgs e) in e:\_Organizado\AERON\Projetos\Visual Studio C#\Relatorio\MyReport\Form1.cs:line 48 
     at System.Windows.Forms.Control.OnClick(EventArgs e) 
     at System.Windows.Forms.Button.OnClick(EventArgs e) 
     at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) 
     at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 
     at System.Windows.Forms.Control.WndProc(Message& m) 
     at System.Windows.Forms.ButtonBase.WndProc(Message& m) 
     at System.Windows.Forms.Button.WndProc(Message& m) 
     at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
     at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
     at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 
     at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 
     at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) 
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) 
     at System.Windows.Forms.Application.Run(Form mainForm) 
     at MyReport.Program.Main() in e:\_Organizado\AERON\Projetos\Visual Studio C#\Relatorio\MyReport\Program.cs:line 19 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: Microsoft.ReportingServices.ReportProcessing.ReportProcessingException 
     HResult=-2146233088 
     Message=One or more parameters required to run the report have not been specified. 
     Source=Microsoft.ReportViewer.Common 
     ExceptionLevelHelpLink=http://go.microsoft.com/fwlink/?LinkId=20476&EvtSrc=Microsoft.ReportingServices.Diagnostics.Utilities.ErrorStrings&EvtID=rsParametersNotSpecified&ProdName=Microsoft%20SQL%20Server%20Reporting%20Services&ProdVer=1.0 
     SkipTopLevelMessage=false 
     StackTrace: 
      at Microsoft.ReportingServices.ReportProcessing.Execution.RenderReport.ValidateReportParameters() 
      at Microsoft.ReportingServices.ReportProcessing.Execution.RenderReportOdpInitial.PrepareForExecution() 
      at Microsoft.ReportingServices.ReportProcessing.Execution.RenderReport.Execute(IRenderingExtension newRenderer) 
      at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.RenderReport(IRenderingExtension newRenderer, DateTime executionTimeStamp, ProcessingContext pc, RenderingContext rc, IChunkFactory yukonCompiledDefinition) 
      at Microsoft.Reporting.LocalService.CreateSnapshotAndRender(ReportProcessing repProc, IRenderingExtension renderer, ProcessingContext pc, RenderingContext rc, SubreportCallbackHandler subreportHandler, ParameterInfoCollection parameters, DatasourceCredentialsCollection credentials) 
      at Microsoft.Reporting.LocalService.Render(String format, String deviceInfo, String paginationMode, Boolean allowInternalRenderers, IEnumerable dataSources, CreateAndRegisterStream createStreamCallback) 
      at Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings) 
     InnerException: 
0

我解決了這個問題。

發生在我的報告中,因爲我在測試中放置了兩個參數,而我只是將數據傳遞給其中一個參數。

在我的報告中創建了「名稱」和「測試」參數,我只是傳遞了「名稱」的值。

listReportParameter.Add (new ReportParameter ("Name", this.textBox1.Text)); 

當我刪除它的工作報告中的「測試」參數。

由於