Search code examples
asp.net.netcrystal-reports

asp.net Crystal Reports, Database Logon Failed


I can't get this report exported as a pdf. I've done this many times before, but now I hit a brick wall. any help would be appreciated.

This is on a windows 7 64 bit machine.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Database logon failed.

Source Error: 



Line 25:         exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat
Line 26:         exportOpts.ExportFormatOptions = pdfOpts
Line 27:         report.ExportToHttpResponse(exportOpts, Response, False, "")
Line 28: 
Line 29:     End Sub

Stack Trace: 



[COMException (0x8004100f): Database logon failed.]
   CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext) +0
   CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) +519

[LogOnException: Database logon failed.]
   CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e) +1243
   CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) +621
   CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext) +1201
   CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportOptions options) +150
   CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToHttpResponse(ExportOptions options, HttpResponse response, Boolean asAttachment, String attachmentName) +212
   reports_CreateReport.generateReport(DataSet ds, String reportpath, ArrayList params) in C:\Users\boruch\Dropbox\Korns-ConnectionStr\reports\CreateReport.aspx.vb:27
   reports_CreateReport.btn_GenReport_Click(Object sender, EventArgs e) in C:\Users\boruch\Dropbox\Korns-ConnectionStr\reports\CreateReport.aspx.vb:58
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9552602
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18044 

Solution

  • I'm going to go ahead and post what I have so that maybe it'll help you. We gave up on Crystal because it was just too sketchy (I believe the first time the export would fail and then it would work every time after that until the app shut down) and SAP basically told us they didn't care if we took a hike, so we did. We switched to SSRS and are far happier for it... But I digress.

    You don't show a lot of code, so I don't know if this is how yours is working. Also, mine is C#, so you'll need to convert... But hopefully you can find the solution to your problem somewhere in this example. I imagine it's going to be in the setting of the credentials...

    Load the document:

    ReportDocument rd = new ReportDocument();
    rd.Load(rptFile);
    

    Set credentials

    ConnectionInfo connectInfo = new ConnectionInfo()
    {
        ServerName = dbServer,
        DatabaseName = "",
        UserID = userId,
        Password = password
    };
    rd.SetDatabaseLogon(userId, password);
    foreach (Table tbl in rd.Database.Tables)
    {
        tbl.LogOnInfo.ConnectionInfo = connectInfo;
        tbl.ApplyLogOnInfo(tbl.LogOnInfo);
    }
    

    Then setup the export:

    DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
    ExportOptions CrExportOptions;
    PdfRtfWordFormatOptions pdfFormatOptions = new PdfRtfWordFormatOptions();
    CrDiskFileDestinationOptions.DiskFileName = outputPath;
    CrExportOptions = rd.ExportOptions;
    {
        CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
        CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
        CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
        CrExportOptions.FormatOptions = pdfFormatOptions;
    }
    

    Supply report parameters

    SetCurrentValuesForParameterField(rd, "IP_COMP_CODE", cc);
    SetCurrentValuesForParameterField(rd, "IP_YEAR", yr);
    SetCurrentValuesForParameterField(rd, "IP_WEEK", wk);
    

    and export...

    rd.Export();
    

    And the implementation for SetCurrentValuesForParameterField:

    private void SetCurrentValuesForParameterField(ReportDocument reportDocument, string paramFieldName, int value)
    {
        ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
        parameterDiscreteValue.Value = value;
    
        ParameterValues currentParameterValues = new ParameterValues();
        currentParameterValues.Add(parameterDiscreteValue);
    
        reportDocument.DataDefinition.ParameterFields[paramFieldName].ApplyCurrentValues(currentParameterValues);
    }