Sandeepk1999
asked on
Logon Failed while exporting (Using Dataset)
I get this popular Logon Failed Error when i'm trying to export a report to pdf format. I'm not using the classic connection. I have a dataset created at run-time and setting the SetDataSource to the dataset generated. It works fine when i view using the viewer but gives "Logon Failed" when i'm trying to export. Here is my code.
Dim rpt As New crLocationTags()
Dim ds As New DataSet("authors")
Dim cn As New SqlClient.SqlConnection("c onnection string")
cn.Open()
Dim cd As New SqlClient.SqlCommand("Sele ct * from authors", cn)
Dim sa As New SqlClient.SqlDataAdapter(c d)
sa.Fill(ds, "authors")
ds.Tables(0).TableName = "authors"
rpt.Database.Tables(0).Set DataSource (ds)
Dim strFName As String
Dim sAppPathName As String
sAppPathName = ConfigurationSettings.AppS ettings("A ppPathName ")
strFName = Server.MapPath("/") & sAppPathName & "\Export\" & Session.SessionID & ".pdf"
Dim oExp As New ExportOptions()
Dim oDo As New DiskFileDestinationOptions ()
rpt.Load()
oDo.DiskFileName = strFName
oExp = rpt.ExportOptions
oExp.ExportFormatType = ExportFormatType.PortableD ocFormat
oExp.ExportDestinationType = ExportDestinationType.Disk File
oExp.DestinationOptions = oDo
rpt.FormatEngine.PrintOpti ons.PaperS ize = PaperSize.PaperLetter
rpt.FormatEngine.PrintOpti ons.PaperO rientation = PaperOrientation.Landscape
rpt.Export() ' This is the line i'm getting error on...
Any help is greatly appreciated.
Thanks
Sandeep
Dim rpt As New crLocationTags()
Dim ds As New DataSet("authors")
Dim cn As New SqlClient.SqlConnection("c
cn.Open()
Dim cd As New SqlClient.SqlCommand("Sele
Dim sa As New SqlClient.SqlDataAdapter(c
sa.Fill(ds, "authors")
ds.Tables(0).TableName = "authors"
rpt.Database.Tables(0).Set
Dim strFName As String
Dim sAppPathName As String
sAppPathName = ConfigurationSettings.AppS
strFName = Server.MapPath("/") & sAppPathName & "\Export\" & Session.SessionID & ".pdf"
Dim oExp As New ExportOptions()
Dim oDo As New DiskFileDestinationOptions
rpt.Load()
oDo.DiskFileName = strFName
oExp = rpt.ExportOptions
oExp.ExportFormatType = ExportFormatType.PortableD
oExp.ExportDestinationType
oExp.DestinationOptions = oDo
rpt.FormatEngine.PrintOpti
rpt.FormatEngine.PrintOpti
rpt.Export() ' This is the line i'm getting error on...
Any help is greatly appreciated.
Thanks
Sandeep
ASKER
When i do this it works fine...
Dim rpt As New crLocationTags()
Dim ds As New DataSet("authors")
Dim cn As New SqlClient.SqlConnection("c onnection string")
cn.Open()
Dim cd As New SqlClient.SqlCommand("Sele ct * from authors", cn)
Dim sa As New SqlClient.SqlDataAdapter(c d)
sa.Fill(ds, "authors")
ds.Tables(0).TableName = "authors"
rpt.Database.Tables(0).Set DataSource (ds)
CrystalReportViewer1.Repor tSource = rpt
Sandeep
Dim rpt As New crLocationTags()
Dim ds As New DataSet("authors")
Dim cn As New SqlClient.SqlConnection("c
cn.Open()
Dim cd As New SqlClient.SqlCommand("Sele
Dim sa As New SqlClient.SqlDataAdapter(c
sa.Fill(ds, "authors")
ds.Tables(0).TableName = "authors"
rpt.Database.Tables(0).Set
CrystalReportViewer1.Repor
Sandeep
The initial report setup seems identical to the viewing one.
Can you export to PDF from the viewer?
What version of CR?
mlmcc
Can you export to PDF from the viewer?
What version of CR?
mlmcc
ASKER
I'm using CR included with .NET. I'm getting the error on the export command. I'm using the ASP.NET viewer, it does not include export option.
Sandeep
Sandeep
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I solved this problem.
I recreated the new dataset and new report then everything worked fine. Then went and compared the what the difference was, and found that one of the field name had a space in my dataset.
Still i dont understand how it worked with viewer and failed during export. And another weird thing was it gave "Logon failed" exception, which drives you to wrong direction.
In short, If anyone gets "Logon Failed" exception look into other mistakes like wrongly type field names, invalid object name, etc.. before digging and and changing the code too much.
mlmcc, Thanks for u r help - I'll award you this points to u for looking and into it.
Sandeep
I recreated the new dataset and new report then everything worked fine. Then went and compared the what the difference was, and found that one of the field name had a space in my dataset.
Still i dont understand how it worked with viewer and failed during export. And another weird thing was it gave "Logon failed" exception, which drives you to wrong direction.
In short, If anyone gets "Logon Failed" exception look into other mistakes like wrongly type field names, invalid object name, etc.. before digging and and changing the code too much.
mlmcc, Thanks for u r help - I'll award you this points to u for looking and into it.
Sandeep
Glad I could help
mlmcc
mlmcc
Does the database require a login?
mlmcc