C#中的LocalReports导致Microsoft.Reporting.WinForms.LocalProcessingException
有人知道我如何避开这个错误吗?或者它意味着什么 错误:Microsoft.Reporting.WinForms.LocalProcessingException 内部异常:Microsoft.ReportingServices.ReportProcessing.ProcessingAbortedException (我将完整错误作为注释放在下面代码段的catch块中) 这是我第一次尝试在VS2010中运行本地报表/报表查看器,但是这种渲染方法每次都在爆炸,google似乎没有提供太多帮助 你能发现任何明显的错误吗 仅供参考,未显示的内容是一个非常简单的XSD,其中有一个datatable,填充在用作数据集的代码中,还有一个rdlc文件(报告),其中有一个表,并使用一个数据源和一个数据集(XSD) 谢谢C#中的LocalReports导致Microsoft.Reporting.WinForms.LocalProcessingException,c#,mysql,reporting-services,xsd,localreport,C#,Mysql,Reporting Services,Xsd,Localreport,有人知道我如何避开这个错误吗?或者它意味着什么 错误:Microsoft.Reporting.WinForms.LocalProcessingException 内部异常:Microsoft.ReportingServices.ReportProcessing.ProcessingAbortedException (我将完整错误作为注释放在下面代码段的catch块中) 这是我第一次尝试在VS2010中运行本地报表/报表查看器,但是这种渲染方法每次都在爆炸,google似乎没有提供太多帮助 你能发
class Program
{
private const string UID = "myLogin";
private const string PASSWORD = "myPassword";
private const string IP = "myServerIPaddress";
static void Main(string[] args)
{
Warning[] warnings;
string[] streamIds;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;
try
{
using (MySqlConnection con = GetMySqlConnetion("schools"))
{
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Connection = con;
cmd.CommandText = @"SELECT `venrollmentandmaxenrollment`.`classId`,
`venrollmentandmaxenrollment`.`NumberOfStudentsEnrolled`,
`venrollmentandmaxenrollment`.`NumberOfMaxEnrollments`
FROM `schools`.`venrollmentandmaxenrollment`;";
MySqlDataReader sessionReportReader = cmd.ExecuteReader();
DataSet1 dataSet1 = new DataSet1();
dataSet1.Load(sessionReportReader, System.Data.LoadOption.Upsert, dataSet1.Tables[0].TableName);
ReportViewer viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = "C:\\VS\\TestReports\\TestReports\\Report1.rdlc";
viewer.LocalReport.DataSources.Add(new ReportDataSource(dataSet1.Tables[0].TableName, dataSet1.Tables[0]));
byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
//TODO: do something with bytes, and drag this code back to the main application, once we get this working!
}
}
}
catch (Exception ex)
{
/*
LocalReport.Render always takes us here with this exception:
*
Microsoft.Reporting.WinForms.LocalProcessingException occurred
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)
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.ReportingServices.ReportProcessing.ReportProcessing.RenderReport(IRenderingExtension newRenderer, DateTime executionTimeStamp, ProcessingContext pc, RenderingContext rc, IChunkFactory yukonCompiledDefinition)
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=DataSet1
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:
*/
}
}
public static MySqlConnection GetMySqlConnetion(string DB)
{
string connStr = String.Format(
"SERVER={0}; Port={1}; UID={2}; PASSWORD={3}; DATABASE={4}; pooling={5};",
IP,
"3306",
UID,
PASSWORD,
DB,
"false");
MySqlConnection mycon = null;
try
{
mycon = new MySqlConnection(connStr);
mycon.Open();
}
catch (MySqlException ex)
{
Logger logger = new Logger("Test Reports App");
logger.Log(ex);
}
return mycon;
}
}
创建要将数据绑定到的自定义类
public class MyReportClass
{
public int ID {get;set;}
public string Name {get;set;}
}
然后使用DataReader
//snippet
MySqlDataReader reader = cmd.ExecuteReader();
// add to collection
List<MyReportClass> myReportClassCollection = new List<MyReportClass.();
while (reader.Read())
{
// populate entity
var myReportClass = new MyReportClass();
// set properties, skipping DBNull checking for quickness
myReportClass.ID = (int)reader["ID"];
myReportClass.Name = (string) reader["Name"];
myReportClassCollection.Add(myReportClass);
}
ReportViewer viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = "C:\\VS\\TestReports\\TestReports\\Report1.rdlc";
viewer.LocalReport.DataSources.Add(new ReportDataSource("myDataSource", myReportClassCollection));
//代码片段
MySqlDataReader=cmd.ExecuteReader();
//添加到集合
List myReportClassCollection=new List创建一个自定义类来绑定数据
public class MyReportClass
{
public int ID {get;set;}
public string Name {get;set;}
}
然后使用DataReader
//snippet
MySqlDataReader reader = cmd.ExecuteReader();
// add to collection
List<MyReportClass> myReportClassCollection = new List<MyReportClass.();
while (reader.Read())
{
// populate entity
var myReportClass = new MyReportClass();
// set properties, skipping DBNull checking for quickness
myReportClass.ID = (int)reader["ID"];
myReportClass.Name = (string) reader["Name"];
myReportClassCollection.Add(myReportClass);
}
ReportViewer viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = "C:\\VS\\TestReports\\TestReports\\Report1.rdlc";
viewer.LocalReport.DataSources.Add(new ReportDataSource("myDataSource", myReportClassCollection));
//代码片段
MySqlDataReader=cmd.ExecuteReader();
//添加到集合
List myReportClassCollection=new List我从Render语句中得到一个LocalProcessingException,因为我正在将用户没有写入权限的目录(具体地说,是Program Files(x86)文件夹--OOPS)中的文件渲染到filestream。它在尝试渲染时无法创建文件,因此引发了LocalProcessingException
因此,请检查您试图呈现到的文件/文件流的位置,并检查用户的权限。注意,我的开发机器上没有这个问题,我对几乎所有东西都有完全权限
希望这对其他人有所帮助,即使这是我自己造成的一个相当愚蠢的问题。我从Render语句中得到一个LocalProcessingException,因为我正在将用户没有写入权限的目录(特别是Program Files(x86)文件夹--OOPS)中的文件渲染到filestream。它在尝试渲染时无法创建文件,因此引发了LocalProcessingException
因此,请检查您试图呈现到的文件/文件流的位置,并检查用户的权限。注意,我的开发机器上没有这个问题,我对几乎所有东西都有完全权限
希望这有助于其他人,即使这是我自己造成的一个相当愚蠢的问题。尝试替换这一行
viewer.LocalReport.DataSources.Add(new ReportDataSource(dataSet1.Tables[0].TableName, dataSet1.Tables[0]));
通过这个
viewer.LocalReport.DataSources.Add(new ReportDataSource(dataSet1.DataSetName, dataSet1.Tables[0]));
试着换掉这条线
viewer.LocalReport.DataSources.Add(new ReportDataSource(dataSet1.Tables[0].TableName, dataSet1.Tables[0]));
通过这个
viewer.LocalReport.DataSources.Add(new ReportDataSource(dataSet1.DataSetName, dataSet1.Tables[0]));
我认为不能将数据集
直接绑定到报表数据源
。您需要将其包装为类似于BindingSource
的格式。ReportDataSource采用datatable或IEnumerable类型。我还没试过装订。有必要在这里使用绑定吗?我认为不能将数据集
直接绑定到报表数据源
。您需要将其包装为类似于BindingSource
的格式。ReportDataSource采用datatable或IEnumerable类型。我还没试过装订。有必要在这里使用绑定吗?谢谢,我很感激,但是我在你的代码中遇到了同样的错误。也许问题根本不在于数据源,而在于报告。但是该报告是赤裸裸的,我在这里真的被难住了。删除并在RDLC文件中重新创建数据集,以映射到新生成的类。还要检查RDLC中的表达式。您可能希望首先使用报表查看器以本机方式打开报表,以确保其正确呈现。明白!!将“myDataSource”重命名为“DataSet2”解决了我的问题。显然,此名称必须与rdlc文件中的数据集名称完全相同。与答案中的代码相结合,异常停止。。谢谢你今天的帮助,祝你好运!谢谢,我很感激,但是我在你的代码中遇到了同样的错误。也许问题根本不在于数据源,而在于报告。但是该报告是赤裸裸的,我在这里真的被难住了。删除并在RDLC文件中重新创建数据集,以映射到新生成的类。还要检查RDLC中的表达式。您可能希望首先使用报表查看器以本机方式打开报表,以确保其正确呈现。明白!!将“myDataSource”重命名为“DataSet2”解决了我的问题。显然,此名称必须与rdlc文件中的数据集名称完全相同。与答案中的代码相结合,异常停止。。谢谢你今天的帮助,祝你好运!