简体   繁体   English

在 IIS 中使用 Crystal Reports 部署应用程序

[英]Deploying an app with Crystal Reports in IIS

I am trying to deploy an app that I used Crystal Reports in. I want to say that it works on local host as I am using IIS Express and in staging I am using IIS.我正在尝试部署一个我使用 Crystal Reports 的应用程序。我想说它可以在本地主机上运行,​​因为我使用的是 IIS Express,而在登台时我使用的是 IIS。 This is the main difference that I can think of but just to be sure I want to write out the entire process that have done.这是我能想到的主要区别,但只是为了确定我想写出已经完成的整个过程。

  1. Build Report in Visual Studio在 Visual Studio 中生成报告
  2. Create ODBC Connection on local host在本地主机上创建 ODBC 连接
  3. Run Report in localhost - it works在本地主机中运行报告 - 它有效
  4. publish MVC app发布MVC应用程序
  5. add ODBC connection with same name on server在服务器上添加同名的 ODBC 连接
  6. copy report to correct location on IIS server将报告复制到 IIS 服务器上的正确位置
  7. run app and report app works report doesn't.运行应用程序并报告应用程序工作报告没有。

The log that I am getting is:我得到的日志是:

FATAL 2018-08-28 03:22:30,923 37280ms Log Service GenerateReport - Exception during StringFormat: Index (zero based) must be greater than or equal to zero and less than the size of the argument list. FATAL 2018-08-28 03:22:30,923 37280ms 日志服务 GenerateReport - StringFormat 期间的异常:索引(从零开始)必须大于或等于零且小于参数列表的大小。 Generate Reports at: 8/28/2018 3:22:30 AM, Exception: CrystalDecisions.CrystalReports.Engine.InternalException: Failed to open the connection.生成报告时间:8/28/2018 3:22:30 AM,异常:CrystalDecisions.CrystalReports.Engine.InternalException:无法打开连接。 QuoteReport 5092_4216_{0FAD9DBD-DCD7-4158-816D-56895A79B362}.rpt Details: [Database Vendor Code: 4060 ] ---> System.Runtime.InteropServices.COMException: Failed to open the connection. QuoteReport 5092_4216_{0FAD9DBD-DCD7-4158-816D-56895A79B362}.rpt 详细信息:[数据库供应商代码:4060] ---> System.Runtime.InteropServices.COMException:无法打开连接。 QuoteReport 5092_4216_{0FAD9DBD-DCD7-4158-816D-56895A79B362}.rpt Details: [Database Vendor Code: 4060 ] at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext) at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) --- End of inner exception 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.ReportDocument.ExportToStream(ExportOptions options) at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportFormatType formatType) at QuickQuote.Controllers.ReportsController.GenerateReport(Int32 reportId, String json) in C:\\Users\\James\\Source\\Repos\\QuickQ QuoteReport 5092_4216_{0FAD9DBD-DCD7-4158-816D-56895A79B362}.rpt 详细信息:[数据库供应商代码:4060 ] 在 CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(Exports. ExportRequestContext reqContext) --- 内部异常堆栈跟踪结束 --- 在 CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e) 在 CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) 在 CrystalDecisions.CrystalReports.portEngine.FormatEngine(StreamEngine.Ex) ExportRequestContext reqContext) at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportOptions options) at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportFormatType formatType) at QuickQuote.Controllers.ReportsController.GenerateReport(Int32) int32 报告Id,字符串\\用户\\James\\Source\\Repos\\QuickQ uote3\\QuickQuote\\Controllers\\ReportsController.cs:line 84{} uote3\\QuickQuote\\Controllers\\ReportsController.cs:line 84{}

Can someone please tell me what my issue is?有人可以告诉我我的问题是什么吗? I have google this error and I don't understand what my issue is.我有谷歌这个错误,我不明白我的问题是什么。

try
{ 
    var stream = _reportBuilder.BuildReport(dataSet, report, filePath, parameters);
    stream.Seek(0, SeekOrigin.Begin);

    return File(stream, "application/pdf", $"Quote{report.Name}-{DateTime.Now}.pdf");
}
catch (Exception e)
{
    _loggingService.FatalFormat($"Generate Reports at: {DateTime.Now}, Exception: {e}");
    throw;
}

Inside reportBuilder.BuildReport is where it is breaking.reportBuilder.BuildReport里面是它被破坏的地方。 I'm sure that it is this line:我确定这是这一行:

var stream = reportDocument.ExportToStream(ExportFormatType.PortableDocFormat);

BuildReport method:构建报告方法:

public Stream BuildReport(DataSet dataSet, Report report, string path, string parameters)
{
    var reportDocument = new ReportDocument();
    reportDocument.Load(path);
    reportDocument.SetDataSource(dataSet);
    AddParametersToReport(ref reportDocument, report, parameters);
    return reportDocument.ExportToStream(ExportFormatType.PortableDocFormat);
}

The exception message is Failed to open the connection .异常消息是Failed to open the connection

Verify if System Data Sources are set up correctly in ODBC Data Source Administrator (for both 32-bit and 64-bit).验证是否在 ODBC 数据源管理器中正确设置了系统数据源(32 位和 64 位)。

You may get Database logon failed error, as credentials specified in .rpt file might be invalid for the database.您可能会收到Database logon failed错误,因为 .rpt 文件中指定的凭据可能对数据库无效。 The solution is to provide database credentials in code:解决方案是在代码中提供数据库凭据:

public Stream BuildReport(DataSet dataSet, Report report, string path, string parameters)
{
    try
    {
        var reportDocument = new ReportDocument();
        reportDocument.Load(path);
        reportDocument.SetDataSource(dataSet);
        AddParametersToReport(ref reportDocument, report, parameters);

        // Set database credentials
        reportDocument.SetDatabaseLogon("dbUsername", "dbPassword");

        return ReportDocument.ExportToStream(ExportFormatType.PortableDocFormat);
    }
    catch(Exception ex)
    {
        _loggingService.FatalFormat($"Exception: {ex}");
        throw;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM