FYI - Logon Failed in Crystal.Net having Subreports (Working Code Supplied) 
Author Message
 FYI - Logon Failed in Crystal.Net having Subreports (Working Code Supplied)

Hey all,

This is posted after much testing and searching for an answer to Logon
Failed in Crystal.Net when including sub reports. I do recommend you
look at additional messages just in case but what I found is this:

Scenario, I created a report and subreport which use the same xsd
schema file as the basis for their data (under the ado.net provider).

1. Crystal.Net does not require you to logon to each table as in
previous versions.
2. To use a .Net subreport you should loop through all the sections
(the way we used to for table logons) and when a subreport is found
open the report.
3. After opening the report set the datasource to the subreport.
4. Make sure the dataset is filled using the specific table name.
5. Pass the datasource to the report using the table name.

NOTE: I've kept the table logon information commented out if you are
using an earlier version of Crystal Reports.

Tommie,

**** SAMPLE CODE BELOW ****
'(As always not guaranteed to work in every situation - environments
vary!)
Private Sub LoadReport(ByRef ds As DataSet)
        Dim myPath As String =
Server.MapPath(ConfigurationSettings.AppSettings("AppPath"))
        'Creates a New Report of the type defined in my report
        'Changes to the report require recompiling the program
        Dim myReport As New mktb()
        'Define the tablename from the configuration file
        Dim TBNAME As String =
ConfigurationSettings.AppSettings("TABLENAME")
        'myReport.Load(myPath &
ConfigurationSettings.AppSettings("rptname"))

        myReport.EnableEventLog(CrystalDecisions.Shared.EventLogLevel.LogEngineErrors)
        myReport.EnableEventLog(CrystalDecisions.Shared.EventLogLevel.LogCRPEAPIErrors)

        myReport.SetDataSource(ds.Tables(TBNAME))

        Dim mySection As Section
        Dim mySections As Sections
        Dim myReportObject As ReportObject
        Dim myReportObjects As ReportObjects
        Dim mySubReportObject As SubreportObject
        Dim mySubRepDoc As New ReportDocument()
        'Dim myTable As CrystalDecisions.CrystalReports.Engine.Table
        'Dim myTableLogonInfos As New
CrystalDecisions.Shared.TableLogOnInfos()
        'Dim myConnectionInfo As New
CrystalDecisions.Shared.ConnectionInfo()
        Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
        Dim myDiskFileDestinationOptions As New
CrystalDecisions.Shared.DiskFileDestinationOptions()
        Dim myExportFile As String

        myExportFile = myPath & "output\" & Session.SessionID.ToString
& ".pdf"

        'Dim myLogin As CrystalDecisions.Shared.TableLogOnInfo
        'Dim count As Integer = 0
        'Dim mySERVER As String =
ConfigurationSettings.AppSettings("SERVER")
        'Dim DBNAME As String =
ConfigurationSettings.AppSettings("DBNAME")
        'Dim UID As String = ConfigurationSettings.AppSettings("UID")
        'Dim PWD As String = ConfigurationSettings.AppSettings("PWD")

        ''Sets the login information for the main report
        'For Each myTable In myReport.Database.Tables
        '    myLogin = myTable.LogOnInfo
        '    myLogin.ConnectionInfo.ServerName = mySERVER
        '    myLogin.ConnectionInfo.DatabaseName = DBNAME
        '    myLogin.ConnectionInfo.UserID = UID
        '    myLogin.ConnectionInfo.Password = PWD
        '    myTable.ApplyLogOnInfo(myLogin)
        'Next

        'Declare all of the sections of the main report
        mySections = myReport.ReportDefinition.Sections

        'Loop through the sections in the main report to find the
subreport objects
        'then open the subreport and set the datasource to the
subreport
        For Each mySection In mySections
            myReportObjects = mySection.ReportObjects
            For Each myReportObject In myReportObjects
                If myReportObject.Kind =
ReportObjectKind.SubreportObject Then
                    'Subreport Found - convert the report object to a
sub report type
                    mySubReportObject = CType(myReportObject,
SubreportObject)
                    'Set the specific instance of this subreport
                    mySubRepDoc =
mySubReportObject.OpenSubreport(mySubReportObject.SubreportName)
                    mySubRepDoc.SetDataSource(ds.Tables(TBNAME))
                    ''Set the login information for the current
subreport found - Not Needed in .Net
                    'For Each myTable In mySubRepDoc.Database.Tables
                    '    myLogin = myTable.LogOnInfo
                    '    myLogin.ConnectionInfo.ServerName = mySERVER
                    '    myLogin.ConnectionInfo.DatabaseName = DBNAME
                    '    myLogin.ConnectionInfo.UserID = UID
                    '    myLogin.ConnectionInfo.Password = PWD
                    '    myTable.ApplyLogOnInfo(myLogin)
                    'Next
                End If
            Next
        Next

        myDiskFileDestinationOptions.DiskFileName = myExportFile
        myExportOptions = myReport.ExportOptions

        With myExportOptions
            .DestinationOptions = myDiskFileDestinationOptions
            .ExportDestinationType = .ExportDestinationType.DiskFile
            .ExportFormatType =
CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
        End With

        myReport.Export()

        Response.ClearContent()
        Response.ClearHeaders()
        Response.ContentType = "application/pdf"
        Response.WriteFile(myExportFile)
        Response.Flush()
        Response.Close()
        System.IO.File.Delete(myExportFile)
        ds.Clear()

    End Sub
**** END SAMPLE CODE ****



Sat, 27 Aug 2005 02:00:45 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Logon Failed.. Crystal Reports.Net Error (Code Included)

2. Crystal Report in .NET - Logon Failed Error while Exporting

3. Crystal and .NET: Logon failed

4. Logon failed. Crystal Reports .NET

5. .Net Crystal Viewer Logon Failed

6. Crystal Export works in VB6 but fails in VB.NET

7. Crystal Reports Logon Exception for Subreports

8. MAPI Logon method fails in runtime, but works in debug mode

9. cr.net - Logon Failed

10. Desperately Need HELP!!!!-Crystal Report-Logon Fail - Can anyone even give me a lead

11. Help-"Error5-Logon Failed"-HELP PLease!!!!!!-Crystal Report

12. Logon Failed when exportign crystal report to PDF (or any other format)

 

 
Powered by phpBB® Forum Software