CrystalDecisions.CrystalReports.Engine.LogOnException: Logon faile

G

Guest

OK, I am confused here, so I hope that somebody out there can help me out.

I am trying to run a report allows me to choose the report and then change
the logon info for it.

Noiw before you say anything; I can actually run the exact same code to do
exactly the same things in a windows form; but it won't work if I try to pass
it to a Crystal Web Viewer.

OK this is my code for the Order.aspx page
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Dim DoReport As New Order_Class
DoReport.SetCompany = "BK"
DoReport.SetEmail = "(e-mail address removed)"
DoReport.SetOrderNumber = "223"
Dim szResponse As String = DoReport.CreateOrder()
Dim MyReport As ReportDocument
MyReport = DoReport.EmailPDF

Me.WebViewer.ReportSource = MyReport

End Sub


!! Webviewer is the WebReport Control

And here for completeness is the two subroutines that should change the
logon details
Function EmailPDF() As ReportDocument

'This creates the fucntion that emails the PDF to the customer

Dim exportFilePath As String
Dim oguid As Guid
Dim szFileName As String = oguid.NewGuid.ToString
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table
Dim iCount As Integer

Try



MainReport = ChangeLogOnInfo(MainReport, "HERA", "reporter",
"reporter")

'OK We know set the parameters required by the report

Dim crParameterDiscreteValue As ParameterDiscreteValue
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldLocation As ParameterFieldDefinition
Dim crParameterValues As ParameterValues
crParameterFieldDefinitions =
MainReport.DataDefinition.ParameterFields

crParameterFieldLocation =
crParameterFieldDefinitions.Item("OrderNumber")
crParameterValues = crParameterFieldLocation.CurrentValues
crParameterDiscreteValue = New
CrystalDecisions.Shared.ParameterDiscreteValue
crParameterDiscreteValue.Value = M_OrderNumber
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldLocation.ApplyCurrentValues(crParameterValues)



MainReport = ChangeLogOnInfo(MainReport, "HERA", "reporter",
"reporter")

'MainReport.PrintToPrinter(1, False, 1, 1)
'Try
' Dim sysMessage As New MailMessage
' sysMessage.From = szMailFrom
' sysMessage.To = M_EmailAddress
' sysMessage.Subject = "Confirmation of Order at The Adult Gift
Shop Limited"
' Dim szBody As String
' szBody = szBody & "We enlose a PDF version of your order for
your records." & vbCrLf
' szBody = szBody & "If you do not have adobe acrobat reader
installed please click on the link below to install it" & vbCrLf
' szBody = szBody &
"http://www.adobe.com/products/acrobat/readstep2.html" & vbCrLf & vbCrLf
' szBody = szBody & "Please do not reply to this email address
all emails. Should be addressed to (e-mail address removed)" & vbCrLf
' szBody = szBody & vbCrLf & vbCrLf & "Thankyou for shopping at
the Adult Gift Shop"
' sysMessage.Body = szBody
' Dim sysAttachment As MailAttachment = New
MailAttachment(exportFilePath, MailEncoding.Base64)
' sysMessage.Attachments.Add(sysAttachment)
' SmtpMail.SmtpServer = szMailServer
' SmtpMail.Send(sysMessage)

' If IO.File.Exists(exportFilePath) Then
' IO.File.Delete(exportFilePath)
' End If

'Catch ex As Exception
' EventLog.WriteEntry("KhaosXML", "Unable to email PDF. The
following error occurred " & ex.Message & "Order Number " & M_OrderNumber & "
Email Address " & M_EmailAddress & ".", EventLogEntryType.Error, 1970)
' ErrorMail()
' Exit Function
'End Try

Catch ex As Exception
MsgBox(ex.Message)
End Try


Return MainReport

End Function




Private Function ChangeLogOnInfo(ByVal Report As ReportDocument, ByVal
ServerName As String, ByVal UserName As String, ByVal Password As String) As
ReportDocument


Dim crConnectionInfo As New ConnectionInfo
With crConnectionInfo
.ServerName = ServerName

.UserID = UserName
.Password = Password
End With

Dim crTable As Table
Dim LogOnInfo As TableLogOnInfo
For Each crTable In Report.Database.Tables
LogOnInfo = crTable.LogOnInfo
'Debug.Write(crTable.Name)
''OK If I get this right we dont need to chnage database names
but will need to chnage servers and usernames and passwords as we
'' may have subreports pointing to different areas

'LogOnInfo.ConnectionInfo.DatabaseName = Database

LogOnInfo.ConnectionInfo.ServerName = ServerName
LogOnInfo.ConnectionInfo.UserID = UserName
LogOnInfo.ConnectionInfo.Password = Password
'LogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(LogOnInfo)
Next


'OK AND NOW WE DO THE SUB REPORTS
Dim crReportObject As ReportObject
Dim crReportObjects As ReportObjects
Dim crSection As Section
Dim crSections As Sections
Dim SubReportObject As SubreportObject
Dim subReportDocument As ReportDocument
Dim crSubTable As Table
Dim crSubTables As Tables
Dim crSubLogOnInfo As TableLogOnInfo


crSections = Report.ReportDefinition.Sections

For Each crSection In crSections
crReportObjects = crSection.ReportObjects

For Each crReportObject In crReportObjects

If TypeOf crReportObject Is SubreportObject Then
SubReportObject = CType(crReportObject, SubreportObject)
subReportDocument =
SubReportObject.OpenSubreport(SubReportObject.SubreportName)

crSubTables = subReportDocument.Database.Tables

For Each crSubTable In crSubTables
crSubLogOnInfo = crSubTable.LogOnInfo
crSubLogOnInfo = crTable.LogOnInfo
crSubLogOnInfo.ConnectionInfo.ServerName = ServerName
crSubLogOnInfo.ConnectionInfo.UserID = UserName
crSubLogOnInfo.ConnectionInfo.Password = Password
crSubTable.ApplyLogOnInfo(LogOnInfo)
Next
End If
Next
Next



Return Report

End Function
There are other functions that set other params, but they would just cloud
the issue.

As I say this is the code that I have used several times (especially the
ChangeLogon Function) that also changes the sub report log on info in
subreports, but for the lif eof me I can't get this to work. Any help would
be greatfully received

1.) Should I move all the code out of my class that does the changing of
logoninfo and chooses the reports and put it all in the page load

2.) Is there something esoteric that the Web viewer is expecting me to do



Yours In Anticipation

Alixx Skevington
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top