Winforms 打印到本地打印机时出错

Winforms 打印到本地打印机时出错,winforms,printing,Winforms,Printing,我的用户希望能够直接打印我在VS2010中设计的报告,而不是通过预览报告的过程。我在VS2010中使用报表设计器设计了报表,它创建了一个.rdlc文件。对于我的代码,我使用以下MSDN演练作为示例: 在我的例子中,数据不是在XML文件中,而是从SQL Server数据库检索数据,我有一个.xsd文件,等等。此外,我还将参数传递给报表。将传递的dataset和ReportParameters分配给报表似乎没有问题。这是一段代码,最后一行是发生错误的那一行: 字符串deviceInfo= “”+

我的用户希望能够直接打印我在VS2010中设计的报告,而不是通过预览报告的过程。我在VS2010中使用报表设计器设计了报表,它创建了一个.rdlc文件。对于我的代码,我使用以下MSDN演练作为示例:

在我的例子中,数据不是在XML文件中,而是从SQL Server数据库检索数据,我有一个.xsd文件,等等。此外,我还将参数传递给报表。将传递的dataset和ReportParameters分配给报表似乎没有问题。这是一段代码,最后一行是发生错误的那一行:


字符串deviceInfo=
“”+
“EMF”+
“8.5英寸”+
“11in”+
“0.4英寸”+
“0.5英寸”+
“0.5英寸”+
“0.4英寸”+
"";
警告[]警告
m_streams=新列表()
report.Render(“Image”、deviceInfo、CreateStream、out警告);

下面是我收到的错误消息:

Microsoft.Reporting.WinForms.LocalProcessingException was unhandled Message=An error occurred during local report processing. Source=Microsoft.ReportViewer.WinForms StackTrace: at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings) at Microsoft.Reporting.WinForms.LocalReport.Render(String format, String deviceInfo, PageCountMode pageCountMode, CreateStreamCallback createStream, Warning[]& warnings) at Microsoft.Reporting.WinForms.LocalReport.Render(String format, String deviceInfo, CreateStreamCallback createStream, Warning[]& warnings) at SimpleWinForms.PrintRfsDirectly.Export(LocalReport report) in C:\Users\Rodf\Documents\Visual Studio 2010\Projects\SimpleWinForms\SimpleWinForms\PrintRfsDirectly.cs:line 62 at SimpleWinForms.PrintRfsDirectly..ctor(spRequestForServicesReport2DataTable RfsTable, ReportParameter AmciName, ReportParameter ClientNumberParameter, ReportParameter CaseNumberParameter, ReportParameter ClientNameParameter, String RdlcFileName) in C:\Users\Rodf\Documents\Visual Studio 2010\Projects\SimpleWinForms\SimpleWinForms\PrintRfsDirectly.cs:line 35 at SimpleWinForms.ShowReport.ShowReport_Load(Object sender, EventArgs e) in C:\Users\Rodf\Documents\Visual Studio 2010\Projects\SimpleWinForms\SimpleWinForms\ShowReport.cs:line 54 at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at System.Windows.Forms.Form.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.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow) at System.Windows.Forms.Control.SetVisibleCore(Boolean value) at System.Windows.Forms.Form.SetVisibleCore(Boolean value) at System.Windows.Forms.Control.Show() at SimpleWinForms.Form1.btnPrintRFS_Click(Object sender, EventArgs e) in C:\Users\Rodf\Documents\Visual Studio 2010\Projects\SimpleWinForms\SimpleWinForms\Form1.cs:line 55 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.PerformClick() at System.Windows.Forms.Form.ProcessDialogKey(Keys keyData) at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData) at System.Windows.Forms.Control.PreProcessMessage(Message& msg) at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg) at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg) at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FPreTranslateMessage(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 SimpleWinForms.Program.Main() in c:\users\rodf\documents\visual studio 2010\Projects\SimpleWinForms\SimpleWinForms\Program.cs:line 18 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.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: Microsoft.ReportingServices.ReportProcessing.ProcessingAbortedException Message=An error has occurred during report processing. Source=Microsoft.ReportViewer.Common ExceptionLevelHelpLink=http://go.microsoft.com/fwlink/?LinkId=20476&EvtSrc=Microsoft.ReportingServices.Diagnostics.Utilities.ErrorStrings&EvtID=rsProcessingAborted&ProdName=Microsoft%20SQL%20Server%20Reporting%20Services&ProdVer=1.0 SkipTopLevelMessage=false StackTrace: at Microsoft.ReportingServices.OnDemandProcessing.OnDemandProcessingContext.AbortHelper.ThrowAbortException(String reportUniqueName) at Microsoft.ReportingServices.OnDemandProcessing.OnDemandProcessingContext.CheckAndThrowIfAborted() at Microsoft.ReportingServices.OnDemandProcessing.RetrievalManager.FetchData(Boolean mergeTran) at Microsoft.ReportingServices.OnDemandProcessing.RetrievalManager.PrefetchData(ReportInstance reportInstance, ParameterInfoCollection parameters, Boolean mergeTran) at Microsoft.ReportingServices.OnDemandProcessing.Merge.FetchData(ReportInstance reportInstance, Boolean mergeTransaction) at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.ProcessOdpReport(Report report, OnDemandMetadata odpMetadataFromSnapshot, ProcessingContext pc, Boolean snapshotProcessing, Boolean reprocessSnapshot, Boolean processUserSortFilterEvent, Boolean processWithCachedData, ErrorContext errorContext, DateTime executionTime, IChunkFactory cacheDataChunkFactory, StoreServerParameters storeServerParameters, GlobalIDOwnerCollection globalIDOwnerCollection, SortFilterEventInfoMap oldUserSortInformation, EventInformation newUserSortInformation, String oldUserSortEventSourceUniqueName, ExecutionLogContext executionLogContext, OnDemandProcessingContext& odpContext) at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.RenderReport(IRenderingExtension newRenderer, DateTime executionTimeStamp, ProcessingContext pc, RenderingContext rc, IChunkFactory cacheDataChunkFactory, IChunkFactory yukonCompiledDefinition, Boolean& dataCached) at Microsoft.Reporting.LocalService.CreateSnapshotAndRender(CatalogItemContextBase itemContext, ReportProcessing repProc, IRenderingExtension renderer, ProcessingContext pc, RenderingContext rc, SubreportCallbackHandler subreportHandler, ParameterInfoCollection parameters, DatasourceCredentialsCollection credentials) at Microsoft.Reporting.LocalService.Render(CatalogItemContextBase itemContext, Boolean allowInternalRenderers, ParameterInfoCollection reportParameters, IEnumerable dataSources, DatasourceCredentialsCollection credentials, CreateAndRegisterStream createStreamCallback, ReportRuntimeSetup runtimeSetup) at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings) InnerException: Microsoft.ReportingServices.ReportProcessing.ReportProcessingException Message=RfsDataSet Source=Microsoft.ReportViewer.Common ExceptionLevelHelpLink=http://go.microsoft.com/fwlink/?LinkId=20476&EvtSrc=Microsoft.ReportingServices.Diagnostics.Utilities.ErrorStrings&EvtID=rsErrorCreatingDataReader&ProdName=Microsoft%20SQL%20Server%20Reporting%20Services&ProdVer=1.0 SkipTopLevelMessage=false StackTrace: at Microsoft.ReportingServices.OnDemandProcessing.RuntimeDataSet.RunDataSetQuery() at Microsoft.ReportingServices.OnDemandProcessing.TablixProcessing.RuntimeOnDemandDataSet.Process() at Microsoft.ReportingServices.OnDemandProcessing.RuntimeDataSet.ProcessConcurrent(Object threadSet) InnerException: 未处理Microsoft.Reporting.WinForms.LocalProcessingException 消息=本地报表处理过程中发生错误。 Source=Microsoft.ReportViewer.WinForms 堆栈跟踪: 在Microsoft.Reporting.WinForms.LocalReport.InternalRender(字符串格式、布尔AllowenterRenders、字符串设备信息、PageCountMode PageCountMode、CreateAndRegisterStream createStreamCallback、警告[]和警告) 位于Microsoft.Reporting.WinForms.LocalReport.Render(字符串格式、字符串设备信息、PageCountMode PageCountMode、CreateStreamCallback createStream、警告[]和警告) 位于Microsoft.Reporting.WinForms.LocalReport.Render(字符串格式、字符串设备信息、CreateStreamCallback createStream、警告[]和警告) 在C:\Users\Rodf\Documents\Visual Studio 2010\Projects\SimpleInforms\SimpleInforms\PrintRfsDirectly.cs中的SimpleInforms.PrintRfsDirectly.Export(LocalReport报表)中:第62行 在SimpleInforms.PrintRfsDirectly..ctor(spRequestForServicesReport2DataTable RfsTable、ReportParameter AmciName、ReportParameter ClientNumberParameter、ReportParameter CaseNumberParameter、ReportParameter ClientNameParameter、String RdlcFileName)在C:\Users\Rodf\Documents\Visual Studio 2010\Projects\SimpleInfo\SimpleInfo\PrintRfsDirectly.cs中:第35行 在C:\Users\Rodf\Documents\Visual Studio 2010\Projects\SimpleInforms\SimpleInforms\ShowReport.ShowReport中加载(对象发送方,事件参数e):第54行 在System.Windows.Forms.Form.OnLoad(EventArgs e)中 在System.Windows.Forms.Form.OnCreateControl()中 位于System.Windows.Forms.Control.CreateControl(布尔值不可修改) 在System.Windows.Forms.Control.CreateControl()中 在System.Windows.Forms.Control.WmShowWindow(Message&m)中 位于System.Windows.Forms.Control.WndProc(Message&m) 在System.Windows.Forms.ScrollableControl.WndProc(Message&m)中 在System.Windows.Forms.Form.WmShowWindow(消息和消息) 在System.Windows.Forms.Form.WndProc(Message&m)中 在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)中 在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)中 在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd、Int32 msg、IntPtr wparam、IntPtr lparam) 位于System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd,Int32 nCmdShow) 位于System.Windows.Forms.Control.SetVisibleCore(布尔值) 位于System.Windows.Forms.Form.SetVisibleCore(布尔值) 在System.Windows.Forms.Control.Show()中 在SimpleInforms.Form1.btnPrintRFS\u中,单击C:\Users\Rodf\Documents\Visual Studio 2010\Projects\SimpleInforms\SimpleInforms\Form1.cs中的(对象发送方,事件参数e):第55行 在System.Windows.Forms.Control.OnClick(EventArgs e)中 在System.Windows.Forms.Button.OnClick(EventArgs e)中 在System.Windows.Forms.Button.PerformClick()中 位于System.Windows.Forms.Form.ProcessDialogKey(Keys keyData) 位于System.Windows.Forms.Control.ProcessDialogKey(Keys keyData) 在System.Windows.Forms.Control.PreProcessMessage(消息和消息)中 位于System.Windows.Forms.Control.PreProcessControlMessageInternal(控制目标、消息和消息) 在System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG&MSG)中 在System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafentiveMethods.IMsoComponent.FPreTranslateMessage(MSG&MSG)中 位于System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafentiveMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID、Int32 reason、Int32 pvLoopData) 位于System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32原因,ApplicationContext上下文) 位于System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32原因,ApplicationContext上下文) 在System.Windows.Forms.Application.Run(Form mainForm)中 在c:\users\rodf\documents\visual studio 2010\Projects\SimpleInfo\SimpleInfo\Program.cs中的simpleInfo.Program.Main()处:第18行 位于System.AppDomain.\u nExecuteAssembly(RuntimeAssembly程序集,字符串[]args) 位于System.AppDomain.ExecuteAssembly(字符串汇编文件、证据汇编安全性、字符串[]args) 在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()上 位于System.Threading.ThreadHelper.ThreadStart\u上下文(对象状态) 在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔ignoreSyncCtx) 在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态) 位于System.Threading.ThreadHelper.ThreadStart()处 InnerException:Microsoft.ReportingServices.ReportProcessing.ProcessingAbortedException 消息=报告期间发生错误
    // Routine to provide to the report renderer, in order to save an image for each page of the report.
    private Stream CreateStream(string name, string fileNameExtension, Encoding encoding,
      string mimeType, bool willSeek)
    {            
        Stream stream = new FileStream(Path.GetTempFileName(), FileMode.Create);            
        m_streams.Add(stream);
        return stream;
    }