M
Michael Persaud
hello,
i am having problems with loading a crystal report in asp.net, below is the
code, the error message.
for shorts the following is bugging
st = oRpt.FormatEngine.ExportToStream(req)
please help,
its been 2 days now and i cant figure this
Thanks
MP
code
==============================
Dim str As String = "'0','2','7'"
CrystalReportViewer1.ReportSource = Server.MapPath("admin_print.rpt")
If Not Me.IsPostBack Then
Dim Ods As DataSet
Try
oRpt = New ReportDocument
oRpt.Load(Server.MapPath("admin_print.rpt"))
'Ods = dg.DataSource
Ods = getData(str)
'Response.Write(Ods.Tables.Count.ToString)
oRpt.SetDataSource(Ods)
Call ExportToPDF() ' this inititiates the next sub where it fails
Catch oException As Exception
'Throw oException
Response.Write(oException.ToString)
Finally
oRpt.Dispose()
'Ods.Dispose()
'Ods.Clear()
End Try
End If
Private Sub ExportToPDF()
Dim tblCurrent As CrystalDecisions.CrystalReports.Engine.Table
Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo
For Each tblCurrent In oRpt.Database.Tables
tliCurrent = tblCurrent.LogOnInfo
With tliCurrent.ConnectionInfo
'get log in info from web.config
..ServerName = ConfigurationSettings.AppSettings("SQLServer")
..DatabaseName = ConfigurationSettings.AppSettings("Database")
..UserID = ConfigurationSettings.AppSettings("UserId")
..Password = ConfigurationSettings.AppSettings("Password")
End With
'apply the log in info
tblCurrent.ApplyLogOnInfo(tliCurrent)
Next tblCurrent
Dim crExportOptions As ExportOptions
Dim st As System.IO.Stream
crExportOptions = oRpt.ExportOptions
With crExportOptions
..FormatOptions = New PdfRtfWordFormatOptions
..ExportFormatType = ExportFormatType.PortableDocFormat
End With
Dim req As ExportRequestContext = New ExportRequestContext
req.ExportInfo = crExportOptions
st = oRpt.FormatEngine.ExportToStream(req)
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Dim b(st.Length) As Byte
st.Read(b, 0, st.Length)
Response.BinaryWrite(b)
End Sub
===============
error stack
===================================
Logon failed.
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: CrystalDecisions.CrystalReports.Engine.LogOnException:
Logon failed.
i am having problems with loading a crystal report in asp.net, below is the
code, the error message.
for shorts the following is bugging
st = oRpt.FormatEngine.ExportToStream(req)
please help,
its been 2 days now and i cant figure this
Thanks
MP
code
==============================
Dim str As String = "'0','2','7'"
CrystalReportViewer1.ReportSource = Server.MapPath("admin_print.rpt")
If Not Me.IsPostBack Then
Dim Ods As DataSet
Try
oRpt = New ReportDocument
oRpt.Load(Server.MapPath("admin_print.rpt"))
'Ods = dg.DataSource
Ods = getData(str)
'Response.Write(Ods.Tables.Count.ToString)
oRpt.SetDataSource(Ods)
Call ExportToPDF() ' this inititiates the next sub where it fails
Catch oException As Exception
'Throw oException
Response.Write(oException.ToString)
Finally
oRpt.Dispose()
'Ods.Dispose()
'Ods.Clear()
End Try
End If
Private Sub ExportToPDF()
Dim tblCurrent As CrystalDecisions.CrystalReports.Engine.Table
Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo
For Each tblCurrent In oRpt.Database.Tables
tliCurrent = tblCurrent.LogOnInfo
With tliCurrent.ConnectionInfo
'get log in info from web.config
..ServerName = ConfigurationSettings.AppSettings("SQLServer")
..DatabaseName = ConfigurationSettings.AppSettings("Database")
..UserID = ConfigurationSettings.AppSettings("UserId")
..Password = ConfigurationSettings.AppSettings("Password")
End With
'apply the log in info
tblCurrent.ApplyLogOnInfo(tliCurrent)
Next tblCurrent
Dim crExportOptions As ExportOptions
Dim st As System.IO.Stream
crExportOptions = oRpt.ExportOptions
With crExportOptions
..FormatOptions = New PdfRtfWordFormatOptions
..ExportFormatType = ExportFormatType.PortableDocFormat
End With
Dim req As ExportRequestContext = New ExportRequestContext
req.ExportInfo = crExportOptions
st = oRpt.FormatEngine.ExportToStream(req)
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Dim b(st.Length) As Byte
st.Read(b, 0, st.Length)
Response.BinaryWrite(b)
End Sub
===============
error stack
===================================
Logon failed.
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: CrystalDecisions.CrystalReports.Engine.LogOnException:
Logon failed.