本文介绍了流到PDF错误(VS.NET 2005)(CR XI Release 2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 你好。我正在使用VS.NET 2005和Crystal Reports XI Release 2(v11.5)。我正在尝试将PDF流回客户端。我必须将文件流回来的代码在CR10上工作正常,但是在CRXI中引发了运行时异常。当我声明内存流时,它是正确的。我已经包含了我的代码和我收到的运行时异常。运行时异常表明它是数据库登录失败,这是不正确的,因为我使用跟踪运行应用程序并看到它登录并执行正确的存储过程。过去3天我一直在努力解决这个错误,所以任何想法或输入都会有所帮助。Hello. I am using VS.NET 2005 and Crystal Reports XI Release 2 (v11.5). I am trying to stream back a PDF to the client. The code that I have to stream the file back, works on CR10 fine, but throws a runtime exception with CRXI. It is right when I declare the memory stream. I have included my code and the runtime exception that I am receiving. The runtime exception says that it is a database logon failure, which is not true because I ran the app with trace and saw it login and execute the correct stored procedures. I have been struggling with this error for the past 3 days, so any thoughts or input would help.谢谢。 Blake 代码 protected void LoadReport()protected void LoadReport() { if (会话[ "ePowerQuoteFormID" ] == null )if (Session["ePowerQuoteFormID"] == null) { Label1.Text = "错误!" ; Label1.Text = "Error!"; Label2.Text = "找不到您的参考ID。" ; Label2.Text = "Your reference ID could not be found."; return ; return;} string id = Session [ "ePowerQuoteFormID" ]。ToString(); string id = Session["ePowerQuoteFormID"].ToString(); string reportPath ; string reportPath; SqlConnection conn = new SqlConnection (); SqlConnection conn = new SqlConnection(); DataSet ds = new DataSet (); DataSet ds = new DataSet(); string strESID = "" ; string strESID = ""; SqlParameter ePowerQuoteFormID = new SqlParameter (); SqlParameter ePowerQuoteFormID = new SqlParameter(); ePowerQuoteFormID.ParameterName = "@ EPowerQuoteFormID" ; ePowerQuoteFormID.ParameterName = "@EPowerQuoteFormID"; ePowerQuoteFormID.Value = id; ePowerQuoteFormID.Value = id; if ( ConfigurationManager .AppSettings [ "ProgramMode" ] == "debug" ) if (ConfigurationManager.AppSettings["ProgramMode"] == "debug") { reportPath = ConfigurationManager .AppSettings [ "debugReportPath" ]; reportPath = ConfigurationManager.AppSettings["debugReportPath"];} else else { reportPath = ConfigurationManager .AppSettings [ "prodReportPath" ]; reportPath = ConfigurationManager.AppSettings["prodReportPath"];} crReportDocument.Load(reportPath); crReportDocument.Load(reportPath); // =========================== Connection === ========= ========================== // =========================== Connection ====================================== if ( ConfigurationManager .AppSettings [ "ProgramMode" ] == "debug" )if (ConfigurationManager.AppSettings["ProgramMode"] == "debug") { crConnectionInfo.ServerName = ConfigurationManager .AppSettings [ "DebugServerName" ]; crConnectionInfo.ServerName = ConfigurationManager.AppSettings["DebugServerName"]; crConnectionInfo.DatabaseName = ConfigurationManager .AppSettings [ "DebugDatabaseName" ]; crConnectionInfo.DatabaseName = ConfigurationManager.AppSettings["DebugDatabaseName"]; conn.ConnectionString = ConfigurationManager .AppSettings [ "debugConn" ]; conn.ConnectionString = ConfigurationManager.AppSettings["debugConn"];} else else { crConnectionInfo.ServerName = ConfigurationManager .AppSettings [ "ServerName" ]; crConnectionInfo.ServerName = ConfigurationManager.AppSettings["ServerName"]; crConnectionInfo.DatabaseName = ConfigurationManager .AppSettings [ "DatabaseName" ]; crConnectionInfo.DatabaseName = ConfigurationManager.AppSettings["DatabaseName"]; conn.ConnectionString = ConfigurationManager .AppSettings [ "productionConn" ]; conn.ConnectionString = ConfigurationManager.AppSettings["productionConn"];} ds = SqlHelper .ExecuteDataset(conn, CommandType .StoredProcedure, ConfigurationManager .AppSettings [ "storedProcGetESIDs" ],ePowerQuoteFormID); ds = SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, ConfigurationManager.AppSettings["storedProcGetESIDs"], ePowerQuoteFormID); crConnectionInfo.UserID = "user" ; crConnectionInfo.UserID = "user"; crConnectionInfo.Password = "xxxxxxxxx" ; crConnectionInfo.Password = "xxxxxxxxx"; crDatabase = crReportDocument.Database; crDatabase = crReportDocument.Database; crTables = crDatabase.Tables; crTables = crDatabase.Tables; for ( int i = 0;我< crTables.Count; i ++)for (int i = 0; i < crTables.Count; i++) { crTable = crTables ; crTable = crTables; crTableLogOnInfo = crTable.LogOnInfo; crTableLogOnInfo = crTable.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectionInfo; crTableLogOnInfo.ConnectionInfo = crConnectionInfo; crTable。 ApplyLogOnInfo(crTableLogOnInfo); crTable.ApplyLogOnInfo(crTableLogOnInfo);} crReportDocument.SetParameterValue( "ePowerQuoteFormID" ,id); crReportDocument.SetParameterValue("ePowerQuoteFormID", id); crReportDocument.SetParameterValue( "SubePowerQuoteFormID" ,id); crReportDocument.SetParameterValue("SubePowerQuoteFormID", id); crReportDocument.SetParameterValue( "chkTXU" ,sUnchecked); crReportDocument.SetParameterValue("chkTXU", sUnchecked); crReportDocument.SetParameterValue( "chkAEP" ,sUnchecked) ; crReportDocument.SetParameterValue("chkAEP", sUnchecked); crReportDocument.SetParameterValue( "chkCenterPoint" ,sUnchecked); crReportDocument.SetParameterValue("chkCenterPoint", sUnchecked); crReportDocument.SetParameterValue( "chkTNMP" ,sUnchecked); crReportDocument.SetParameterValue("chkTNMP", sUnchecked); crReportDocument.SetParameterValue( "chkSharyland" ,sUnchecked); crReportDocument.SetParameterValue("chkSharyland", sUnchecked); crReportDocument.SetParameterValue( "chkEntergyTexas" ,sUnchecked); crReportDocument.SetParameterValue("chkEntergyTexas", sUnchecked); for ( int i = 0;我< ds.Tables [0] .Rows.Count; i ++)for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { strESID = ds.Tables [0] .Rows [ "ESID" ]。ToString(); strESID = ds.Tables[0].Rows["ESID"].ToString(); if ((strESID.StartsWith( " 1044372" ))||(strESID.StartsWith( "101769" )) )if ((strESID.StartsWith("1044372")) || (strESID.StartsWith("101769"))) crReportDocument.SetParameterValue( "chkTXU" ,sChecked); crReportDocument.SetParameterValue("chkTXU", sChecked); if ((strESID.StartsWith( "100327" ))|| strESID.StartsWith( "102040" ))if ((strESID.StartsWith("100327")) || strESID.StartsWith("102040")) crReportDocument.SetParameterValue( "chkAEP" ,sChecked); crReportDocument.SetParameterValue("chkAEP", sChecked); if (strESID.St artsWith( "100890" ))if (strESID.StartsWith("100890")) crReportDocument.SetParameterValue( "chkCenterPoint" ,sChecked); crReportDocument.SetParameterValue("chkCenterPoint", sChecked); if (strESID.StartsWith( "104005" ))if (strESID.StartsWith("104005")) crReportDocument.SetParameterValue( "chkTNMP" ,sChecked); crReportDocument.SetParameterValue("chkTNMP", sChecked);} MemoryStream oStream =( MemoryStream )crReportDocument.ExportToStream(CrystalDecisions.Shared。 ExportFormatType .HTML32); MemoryStream oStream = (MemoryStream)crReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.HTML32); Response.ClearContent(); Response.ClearContent(); Response.ClearHeaders(); Response.ClearHeaders(); Response.ContentType = "application / pdf" ; Response.ContentType = "application/pdf"; Response.BinaryWri te(oStream.ToArray()); Response.BinaryWrite(oStream.ToArray()); Response.End(); Response.End();} 推荐答案 不清楚为什么要创建DS然后将报告登录信息设置到服务器?Not clear why you are creating a DS and then setting the report logon info to the Server?以下是示例代码做同样的事情,而不是PDF,所以只需进行更改,先将其保存到磁盘,然后将文件流式传输给用户:Here's sample code to do the same, not for PDF so just make the changes, save it to disk first and then stream the file to the user: private void ExportToStream_Click(object sender, EventArgs e){ CrystalDecisions.Shared.MicrosoftMailDestinationOptions mailOpts = CrystalDecisions.Shared.ExportOptions.CreateMicrosoftMailDestinationOptions(); CrystalDecisions.Shared.DiskFileDestinationOptions diskOpts = CrystalDecisions.Shared.ExportOptions.CreateDiskFileDestinationOptions(); CrystalDecisions.Shared.ExportOptions exportOpts = new CrystalDecisions.Shared.ExportOptions(); CrystalDecisions.Shared.CharacterSeparatedValuesFormatOptions csvExpOpts = new CrystalDecisions.Shared.CharacterSeparatedValuesFormatOptions(); CrystalDecisions.Shared.HTMLFormatOptions HTMLExpOpts = new CrystalDecisions.Shared.HTMLFormatOptions(); rpt.Load(@"c:\reports\b.rpt"); //diskOpts.DiskFileName = "c:\\ReportName.csv"; diskOpts.DiskFileName = @"c:\tmp\html\b.html"; exportOpts.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile; //exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.CharacterSeparatedValues; exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.HTML32; exportOpts.ExportDestinationOptions = diskOpts; //csvExpOpts = new CharacterSeparatedValuesFormatOptions(); //csvExpOpts.GroupSectionsOption = CsvExportSectionsOption.Export; //csvExpOpts.ReportSectionsOption = CsvExportSectionsOption.Export; //csvExpOpts.SeparatorText = ","; //csvExpOpts.Delimiter = "|"; HTMLExpOpts = new HTMLFormatOptions(); //HTMLExpOpts.HTMLFileName = @"c:\tmp\html\phonebook report that looks real purdy.html"; HTMLExpOpts.HTMLBaseFolderName = @"c:\tmp\html\b.html"; HTMLExpOpts.HTMLEnableSeparatedPages = false; HTMLExpOpts.UsePageRange = false; HTMLExpOpts.HTMLHasPageNavigator = false; System.IO.Stream oStream; byte[] byteArray = null; //oStream = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.CharacterSeparatedValues); oStream = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.HTML32); byteArray = new byte[oStream.Length]; oStream.Read(byteArray, 0, Convert.ToInt32(oStream.Length - 1)); // this is used to verify the file so I saved it to disk System.IO.File.Create(diskOpts.DiskFileName, Convert.ToInt32(oStream.Length - 1)).Close(); System.IO.File.OpenWrite(diskOpts.DiskFileName).Write(byteArray, 0, Convert.ToInt32(oStream.Length - 1)); System.IO.File.SetAttributes(diskOpts.DiskFileName, System.IO.FileAttributes.Directory); oStream.Close(); GC.Collect(); MessageBox.Show("Export to Stream complete", "RAS", MessageBoxButtons.OK, MessageBoxIcon.Information);} 请务必同时应用所有最新补丁。Be sure to apply all of the latest patches as well. Don 这篇关于流到PDF错误(VS.NET 2005)(CR XI Release 2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-18 17:49