ExporttoPDF()失败,提示“数据库登录失败”;错误
本文关键字:失败 登录 错误 数据库 提示 ExporttoPDF | 更新日期: 2023-09-27 18:03:52
在示例控制台应用程序中,我将xml文件读入数据集,将其提供给Crystal Reports,并使用ExportToPDF()方法将报告导出为PDF。我的应用程序失败,出现"数据库登录失败"错误。在MSDN和SCN上发现的类似问题似乎不起作用。
我在日志中得到以下错误和堆栈跟踪:
ConsolePDF Exception: Database logon failed.
ConsolePDF Inner Exception: System.Runtime.InteropServices.COMException (0x8004100F): Database logon failed.
at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext)
at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)
ConsolePDF Stack Trace: at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e)
at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)
at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext)
at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToDisk(ExportFormatType formatType, String fileName)
at ConsolePDF.Program.ConsolePDF() in D:'user'ConsolePDF2'ConsolePDF'Program.cs:line 519
在程序中,我正在读取XML文件,将其加载到数据集中并将其提供给Crystal的报告(.rpt)文件。在report.ExportToDisk(…):
引发异常try
{
DataSet ds = new DataSet();
ds.ReadXml(fileName, XmlReadMode.ReadSchema);
string pdfFileName = filename + ".pdf";
ReportDocument report = new ReportDocument();
String rptLoc = reportLocation.Replace(@"'/", @"'");
report.Load(rptLoc);
ds.WriteXml(@"C:'Temp'ReportPDFSOXML.xml", XmlWriteMode.WriteSchema);
string fullName = fileDir + pdfFileName;
report.SetDatabaseLogon("user","password","server","database");
// Next line is 519 - where exception was raised
report.ExportToDisk(ExportFormatType.PortableDocFormat, fullName);
report.Close();
report.Dispose();
}
catch (Exception ex)
{
logger.Info(ex.Message, "ConsolePDF Exception");
if (ex.InnerException != null)
{
logger.Info(ex.InnerException.ToString(), "ConsolePDF Inner Exception");
}
if (ex.StackTrace.ToString() != null)
{
logger.Info(ex.StackTrace.ToString(), "ConsolePDF Stack Trace");
}
connPool.Dispose();
sessionConn.Dispose();
Environment.Exit(0);
}
我能做些什么来消除这个错误?
但是您从未在此代码中使用您的数据集!试着像这样添加这一行:
//Your Line
ds.WriteXml(@"C:'Temp'ReportPDFSOXML.xml", XmlWriteMode.WriteSchema);
//Set the report datasource, using your ds
report.SetDataSource(ds);
然后,你检查你的登录/数据库/服务器信息两次吗?问题可能就在那里!
认为,