我有许多报告,以前曾在旧版桌面应用程序中从ODBC源中提取数据。我现在正尝试通过将数据加载到DataTable中来在C#.net服务内填充这些报告。
代码在Windows应用程序中运行正常,但在服务中运行不正常。
我已经尝试同时为该服务编译为x86和x64,并以用于运行桌面应用程序的同一用户身份运行该服务。
摘要:
ReportDocument rd = new ReportDocument(); StreamReader sr = new StreamReader(@"C:\infile.txt"); DataTable dt = new DataTable("REPORTTABLE"); string[] columnNames = new string[3]; columnNames[0] = "COL1"; columnNames[1] = "COL2"; columnNames[2] = "COL3"; foreach (string colName in columnNames) { dt.Columns.Add(colName); } int i = 0; DataRow dr; string[] fields = new string[3]; while (!sr.EndOfStream) { fields[i] = sr.ReadLine(); i++; } dt.Rows.Add(fields); sr.Close(); rd.Load(@"C:\report.rpt"); rd.SetDataSource(dt);
该异常在SetDataSource()处引发。列名称和数据表名称与之前针对ODBC数据源进行验证的名称相同。输入数据是文本文件中每列的一行,例如
data1数据2data3
初始错误是:
Error in File marriage 18884_5280_{F58B98C0-1D10-462C-98F8-88974D74BFF8}.rpt: Failed to load database information.
堆栈跟踪:
at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e) at CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSourceInternal(Object val, Type type) at CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSource(DataSet dataSet) at WindowsService1.Service1.OnTimer(Object sender, ElapsedEventArgs args) in C:\Users\himik\source\repos\WindowsService1\WindowsService1\Service1.cs:line 432
谢谢你。
我有许多报告,以前曾在旧版桌面应用程序中从ODBC源中提取数据。我现在正在尝试通过将数据加载到...
好的,启动Process Explorer后,我找到了解决方案。尽管测试了x86和x64的目标并且没有什么区别,但我发现使用Crystal时,如果在项目的Build属性中选择“首选32位”选项,它仍然会选择x86库。取消选中此选项意味着使用了正确的环境库(在我的情况下为x64),并且报表可以正确运行。