Quantcast
Channel: SCN : Unanswered Discussions - SAP Crystal Reports, version for Visual Studio
Viewing all articles
Browse latest Browse all 2556

Re: Database logon failed when exporting Crystal Report to PDF

$
0
0

I've been chasing a CR error for a while and finally FOUND the answer and I'd thought I'd relay the information to you.

 

A windows application built and deployed using VB in Visual Studio 2010, .net framework 4.

originally using CR for VS 13_0_1.  I was getting intermittent "null reference" exceptions on the EXPORT or getting the infamous "database login" error too ( on export).

 

I inherited the application and the CR reports that were developed for it but eventually I found that despite using the same exact method to load, set the database connection, set the export options and set the report parameters the cause of the Exceptions was...

...

...individually each report was using different underlying connections type.

one report used OLEDB (ADO) and the one that failed was SQLNCLI10.

..

it would be nice to know why when the Connection types were different it would cause the subsequent report to crash.

 

my code is below. I've removed any code not related to Crystal Rpt processing.

 

    Friend Sub CreatePDF_Orig(ByVal zReportName As String, ByVal zInspType As String, ByVal zApplNmbr As String, ByVal zInspNmbr As String, ByVal zCreateDateTime As String, ByVal zIsCOrpt As Boolean)

 

 

        Dim crzReport As New ReportDocument

        Dim sTempPath As String = Nothing, sDocOutPath As String = Nothing

        Dim sCreatePDFDebug As String = Nothing

 

 

        Dim CrzPdfOptions As New PdfFormatOptions

        Dim CrzExportOptions As New ExportOptions

        Dim CrzDiskFileDestinationOptions As New DiskFileDestinationOptions()

        Dim CrzFormatTypeOptions As New PdfRtfWordFormatOptions()

 

 

        Dim sReportOutName As String = Nothing, sReportOutSuffix As String = Nothing

        Dim sImageDocFiles As String() = Nothing

        Dim zFileInfo As IO.FileInfo = Nothing

        Dim bAlreadyExists As Boolean = False

        Dim bAExistsOverwrite As Boolean = False

        Dim bImagesMoved As Boolean = False

 

 

        Dim sDbServer As String = "(local)\SQLEXPRESS", sDbName As String = "DatabaseNameHere"

        Dim cnxInfo As ConnectionInfo = Nothing

 

 

        Try

           ' create directory structure for output documents and path.

            sTempPath = gsMyInspectionsRootPath & "\" & zInspType & "\" & zApplNmbr

            sTempPath = gsMyInspectionsRootPath & "\" & zInspType & "\" & zApplNmbr & "\" & zInspNmbr

 

            sReportOutName = zApplNmbr & "-" & zInspNmbr & "-" & gsUserName & "-" & zCreateDateTime

 

           If zIsCOrpt Then

                sReportOutSuffix = "-CO"

                sDocOutPath = gsMyInspectionsRootPath & "\" & zInspType & "\" & zApplNmbr & "\" & zInspNmbr & "\" & sReportOutName & sReportOutSuffix & ".pdf"

            Else

                sDocOutPath = gsMyInspectionsRootPath & "\" & zInspType & "\" & zApplNmbr & "\" & zInspNmbr & "\" & sReportOutName & ".pdf"

            End If

 

 

            crzReport.Load(zReportName)

 

 

            ' Removes saved data. This causes fresh data to be loaded when the report is subsequently viewed.-- probably not needed.

            ' crzReport.Refresh() '(zReportName)

 

 

            ' version 68... 6/12/2015

            If gsUserName = "ADPJA" Or gsUserName = "PDLDW" Then

                '---------------------------------------------------------------------------------------------------------------------------

                ' Explicit connection to each table in report(s) source from internet.

                '---------------------------------------------------------------------------------------------------------------------------

                Dim crTable As Engine.Table

                Dim crTableLogonInfo As CrystalDecisions.Shared.TableLogOnInfo

                Dim ConnInfo As New CrystalDecisions.Shared.ConnectionInfo

 

 

                ConnInfo.ServerName = sDbServer

                ConnInfo.DatabaseName = sDbName

                ConnInfo.UserID = gCnxDBUser

                ConnInfo.Password = gCnxUserPassword

 

 

                For Each crTable In crzReport.Database.Tables

                    crTableLogonInfo = crTable.LogOnInfo

                    crTableLogonInfo.ConnectionInfo = ConnInfo

                    crTable.ApplyLogOnInfo(crTableLogonInfo)

                Next

                '---------------------------------------------------------------------------------------------------------------------------

            Else

                'crzReport.SetDatabaseLogon(gCnxDBUser, gCnxUserPassword)

                crzReport.SetDatabaseLogon(gCnxDBUser, gCnxUserPassword, "(local)\SQLEXPRESS", "DatabaseNameHere")

            End If

 

 

            '' Checks whether the database connection is active for the report that is loaded by the ReportDocument object.

 

 

            CrzDiskFileDestinationOptions.DiskFileName = sDocOutPath                    'Set the destination path and file name

            CrzExportOptions = crzReport.ExportOptions                                  'Set export options

 

 

            With CrzExportOptions

                .ExportDestinationType = ExportDestinationType.DiskFile ' DiskFile, ExchangeFolder, MicrosoftMail, NoDestination

                .ExportFormatType = ExportFormatType.PortableDocFormat  'ExcelWorkBook, HTML32, HTML40, NoFormat, PDF, RichText, RTPR, TabSeperatedText, Text

                .DestinationOptions = CrzDiskFileDestinationOptions

                .FormatOptions = CrzFormatTypeOptions

            End With

 

 

            If IsNothing(crzReport) Then sCreatePDFDebug &= ", crzReport is Null b4 CRSetParms."

            CRSetParameters(zReportName, crzReport)

 

 

            If IsNothing(crzReport) Then sCreatePDFDebug &= ", crzReport is Null after CRSetParms."

            crzReport.Export()

 

 

 

 

        Catch exc As Exception

                MsgBox("Error in Module1.CreatePDF:" & vbCrLf & exc.ToString)

 

 

        Finally

            crzReport.Close()

            crzReport.Dispose()

 

 

            CrzPdfOptions = Nothing

            CrzExportOptions = Nothing

            CrzDiskFileDestinationOptions = Nothing

            CrzFormatTypeOptions = Nothing

 

 

            Application.DoEvents()        ' 7/8/2015

        End Try

    End Sub

 

Message was edited by: Ludek Uher


Viewing all articles
Browse latest Browse all 2556

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>