Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Login error when trying to export

Status
Not open for further replies.

PT109

Technical User
Feb 11, 2002
9
US
I have downloaded the sample from Crystaldescisions. Their sample works fine on my machine. Mine gives me a login error. I have basically pasted their code into my project.
the differences are theirs is an access Database. Mine is a SQL database. The SQL logon works initailly at least because I can see data in the report.

I am connecting to 1 tabel in the SQL database only.
It seems to fail when it gets to the TRY section of the export report function.

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.IO




Public Class export2
Inherits System.Web.UI.Page
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList

' CR Variables
Dim crReportDocument As ReportDocument
Dim crExportOptions As ExportOptions
Dim crDiskFileDestinationOptions As DiskFileDestinationOptions

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
'Create an instance of the strongly-typed report object


' *******************************************
' Initialize Dropdownlist for Format types
' *******************************************
With DropDownList1.Items
.Add(&quot;&quot;)
.Add(&quot;Rich Text (RTF)&quot;)
.Add(&quot;Portable Document (PDF)&quot;)
.Add(&quot;MS Word (DOC)&quot;)
.Add(&quot;MS Excel (XLS)&quot;)
.Add(&quot;Crystal Report (RPT)&quot;)
.Add(&quot;HTML 3.2 (HTML)&quot;)
.Add(&quot;HTML 4.0 (HTML)&quot;)
End With


End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

Dim logOnInfo As New CrystalDecisions.Shared.TableLogOnInfo()
'Dim oRpt As New RPTexporttest()
'CrystalReportViewer1.ReportSource = oRpt
crReportDocument = New RPTexporttest()
CrystalReportViewer1.ReportSource = crReportDocument
crReportDocument = crReportDocument
logOnInfo = crReportDocument.Database.Tables.Item(&quot;t_server_info&quot;).LogOnInfo
logOnInfo.ConnectionInfo.Password = &quot;PASSWORD&quot;
CrystalReportViewer1.LogOnInfo.Add(logOnInfo)

End Sub

Sub ExportReport()
' This subroutine uses a case statement to determine the selected export format from the dropdownlist
' menu and then sets the appropriate export options for the selected export format. The report is
' exported to a subdirectory called &quot;Exported&quot;.

' ********************************
'Check to see if the application directory has a subdirectory called &quot;Exported&quot;.
'If not, create the directory since exported files will be placed here.
'This uses the Directory class of the System.IO namespace.
Dim ExportPath As String
ExportPath = &quot;c:\oktodel\srts\&quot;
'If Directory.Exists(ExportPath) = False Then
'Directory.CreateDirectory(Request.PhysicalApplicationPath + &quot;Exported\&quot;)
'End If
' ********************************


' First we must create a new instance of the diskfiledestinationoptions class and
' set variable called crExportOptions to the exportoptions class of the reportdocument.
crDiskFileDestinationOptions = New DiskFileDestinationOptions()
crExportOptions = crReportDocument.ExportOptions

'Find the export type specified in the dropdownlist and export the report. The possible export format
'types are Rich Text(RTF), Portable Document (PDF), MS Word (DOC), MS Excel (XLS), Crystal Report (RPT),
'HTML 3.2 (HTML) and HTML 4.0 (HTML)
'
'Though not used in this sample application, there are options that can be specified for various format types.
'When exporting to Rich Text, Word, or PDF, you can use the PdfRtfWordFormatOptions class to specify the
'first page, last page or page range to be exported.
'When exporting to Excel, you can use the ExcelFormatOptions class to specify export properties such as
'the column width etc.

Select Case DropDownList1.SelectedItem.Text 'this contains the value of the selected export format.

Case &quot;Rich Text (RTF)&quot;
'--------------------------------------------------------------------
'Export to RTF.

'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + &quot;RichTextFormat.rtf&quot;

'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.RichText
.DestinationOptions = crDiskFileDestinationOptions
End With
'--------------------------------------------------------------------


'--------------------------------------------------------------------
Case &quot;Portable Document (PDF)&quot;
'Export to PDF


'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + &quot;PortableDoc.pdf&quot;

'set the required report ExportOptions properties
With crExportOptions
.DestinationOptions = crDiskFileDestinationOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
End With
'--------------------------------------------------------------------


'--------------------------------------------------------------------
Case &quot;MS Word (DOC)&quot;
'Export to Word


'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + &quot;Word.doc&quot;

'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.WordForWindows
.DestinationOptions = crDiskFileDestinationOptions
End With
'--------------------------------------------------------------------


'--------------------------------------------------------------------
Case &quot;MS Excel (XLS)&quot;
'Export to Excel

'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + &quot;Excel.xls&quot;

'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.Excel
.DestinationOptions = crDiskFileDestinationOptions
End With
'--------------------------------------------------------------------


'--------------------------------------------------------------------
Case &quot;Crystal Report (RPT)&quot;
'Export to Crystal reports:

'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + &quot;Report.rpt&quot;

'set the required report ExportOptions properties
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.CrystalReport
.DestinationOptions = crDiskFileDestinationOptions
End With
'--------------------------------------------------------------------


'--------------------------------------------------------------------
Case &quot;HTML 3.2 (HTML)&quot;
'Export to HTML32:

Dim HTML32Formatopts As New HTMLFormatOptions()

With crExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.HTML32
End With

With HTML32Formatopts
.HTMLBaseFolderName = ExportPath + &quot;Html32Folder&quot; 'Foldername to place HTML files
.HTMLFileName = &quot;HTML32.html&quot;
.HTMLEnableSeparatedPages = False
.HTMLHasPageNavigator = False
End With

crExportOptions.FormatOptions = HTML32Formatopts
'--------------------------------------------------------------------


'--------------------------------------------------------------------
Case &quot;HTML 4.0 (HTML)&quot;
'Export to Html 4.0:

Dim HTML40Formatopts As New HTMLFormatOptions()

With crExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.HTML40
End With

With HTML40Formatopts
.HTMLBaseFolderName = ExportPath + &quot;Html40Folder&quot; ' Foldername to place HTML files
.HTMLFileName = &quot;HTML40.html&quot;
.HTMLEnableSeparatedPages = True
.HTMLHasPageNavigator = True
.FirstPageNumber = 1
.LastPageNumber = 3
End With

crExportOptions.FormatOptions = HTML40Formatopts

End Select 'export format

'Once the export options have been set for the report, the report can be exported. The Export command
'does not take any arguments
Try
' Export the report
crReportDocument.Export()
Catch err As Exception
Response.Write(&quot;<BR>&quot;)
Response.Write(err.Message.ToString)
End Try

End Sub





Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ExportReport()
End Sub
End Class
 
I think your problem may be that you are not logging into the report before you execute it.

try this to log the report and all subreports into the database:
Code:
Dim crReportDocument As New ReportDocument()
        Dim crTableLogonInfos As New TableLogOnInfos()
        Dim crTableLogonInfo As New TableLogOnInfo()
        Dim crTables As Tables
        Dim crTable As Table
        Dim tmpCounter As Int32
        Dim crSections As Sections
        Dim crSection As Section
        Dim crReportObjects As ReportObjects
        Dim crReportObject As ReportObject
        Dim crSubreportObject As SubreportObject
        Dim crDataBase As Database
        Dim crConnInfo As New ConnectionInfo()
        Dim subRepDoc As New ReportDocument()

        'Logs into the tables in the report
        crReportDocument = rptReport
        crDataBase = crReportDocument.Database
        crTables = crDataBase.Tables
        For Each crTable In crTables
            With crConnInfo
                .ServerName = strServer
                .DatabaseName = strDBase
                .UserID = strUID
                .Password = strPWD
            End With
            crTableLogonInfo = crTable.LogOnInfo
            crTableLogonInfo.ConnectionInfo = crConnInfo
            crTable.ApplyLogOnInfo(crTableLogonInfo)
        Next
        'Logs into the tables in the Sub-reports
        crSections = crReportDocument.ReportDefinition.Sections
        For Each crSection In crSections
            crReportObjects = crSection.ReportObjects
            For Each crReportObject In crReportObjects
                If crReportObject.Kind = ReportObjectKind.SubreportObject Then
                    crSubreportObject = CType(crReportObject, SubreportObject)
                    subRepDoc = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)
                    crDataBase = subRepDoc.Database
                    crTables = crDataBase.Tables
                    For Each crTable In crTables
                        With crConnInfo
                            .ServerName = strServer
                            .DatabaseName = strDBase
                            .UserID = strUID
                            .Password = strPWD
                        End With
                        crTableLogonInfo = crTable.LogOnInfo
                        crTableLogonInfo.ConnectionInfo = crConnInfo
                        crTable.ApplyLogOnInfo(crTableLogonInfo)
                    Next
                End If
            Next
        Next
 
I thought I was loging into the report with this code at the page load. The report does display correctly on the browser.

Dim logOnInfo As New CrystalDecisions.Shared.TableLogOnInfo()
'Dim oRpt As New RPTexporttest()
'CrystalReportViewer1.ReportSource = oRpt
crReportDocument = New RPTexporttest()
CrystalReportViewer1.ReportSource = crReportDocument
crReportDocument = crReportDocument
logOnInfo = crReportDocument.Database.Tables.Item(&quot;t_server_info&quot;).LogOnInfo
logOnInfo.ConnectionInfo.Password = &quot;PASSWORD&quot;
CrystalReportViewer1.LogOnInfo.Add(logOnInfo)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top