Link to home
Start Free TrialLog in
Avatar of Sandeepk1999
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("connection string")
        cn.Open()
        Dim cd As New SqlClient.SqlCommand("Select * from authors", cn)
        Dim sa As New SqlClient.SqlDataAdapter(cd)
        sa.Fill(ds, "authors")

        ds.Tables(0).TableName = "authors"
        rpt.Database.Tables(0).SetDataSource(ds)

        Dim strFName As String
        Dim sAppPathName As String
        sAppPathName = ConfigurationSettings.AppSettings("AppPathName")
        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.PortableDocFormat
        oExp.ExportDestinationType = ExportDestinationType.DiskFile
        oExp.DestinationOptions = oDo

        rpt.FormatEngine.PrintOptions.PaperSize = PaperSize.PaperLetter
        rpt.FormatEngine.PrintOptions.PaperOrientation = PaperOrientation.Landscape
        rpt.Export()          ' This is the line i'm getting error on...


Any help is greatly appreciated.

Thanks
Sandeep
Avatar of Mike McCracken
Mike McCracken

Is this code similar to the code used to open the viewer?

Does the database require a login?

mlmcc
Avatar of Sandeepk1999

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("connection string")
        cn.Open()
        Dim cd As New SqlClient.SqlCommand("Select * from authors", cn)
        Dim sa As New SqlClient.SqlDataAdapter(cd)
        sa.Fill(ds, "authors")

        ds.Tables(0).TableName = "authors"
        rpt.Database.Tables(0).SetDataSource(ds)
       CrystalReportViewer1.ReportSource = rpt

Sandeep
The initial report setup seems identical to the viewing one.

Can you export to PDF from the viewer?

What version of CR?

mlmcc
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
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Glad I could help

mlmcc