0
votes

I was given a task of rewriting some Crystal Reports. I found the original reports circa 1999, opened them up in VS 2008 made the changes and saved them.

Now, they reference a database that is no longer around. So, I deleted this data source and added a .NET OBJECT datasource. I changed everything around so that the fields now look at this new datasource.

My intent was to create the report and during run time, pass it a datatable. This table is created by running a sproc created.

When I run it, I get the first page of the report. But when I try to change pages or print, I get an error:

Logon failed. Details: crdb_adoplus : Object reference not set to an instance of an object. Error in File C:...\MR01 {8E5164A9-4B01-4019-81E6-87AED65A02DF}.rpt: Unable to connect: incorrect log on parameters

Here is my code:

<CR:CrystalReportViewer ID="theCrystalReportViewer" visible="false" runat="server" EnableDatabaseLogonPrompt="false"   />


        Dim theDataTable As DataTable = tbl
        theDataTable.TableName = "tableName"
        Dim oReport As New ReportDocument

        Dim sRptPath As String = "...Reports\MR01.rpt"
        oReport.Load(sRptPath)
        oReport.SetDataSource(theDataTable)
        'oReport.SetDatabaseLogon("####", "####", "####", "#####")


        Dim c As ConnectionInfo = New ConnectionInfo()
        c.ServerName = "####"
        c.DatabaseName = "####"
        c.Password = "####"
        c.UserID = "####"
        c.Type = ConnectionInfoType.SQL
        c.IntegratedSecurity = False

        For i As Integer = 0 To theCrystalReportViewer.LogOnInfo.Count - 1
            theCrystalReportViewer.LogOnInfo(i).ConnectionInfo = c
        Next


        'theCrystalReportViewer.EnableDatabaseLogonPrompt = False
        'theCrystalReportViewer.DisplayGroupTree = False
        theCrystalReportViewer.ReportSource = oReport
        theCrystalReportViewer.DataBind()

        litMsg.Visible = False
        theCrystalReportViewer.Visible = True
2

2 Answers

0
votes

Try following the instructions here: http://vb.net-informations.com/crystal-report/vb.net_crystal_report_without_database.htm

I think you will need to get rid of this too:

    Dim c As ConnectionInfo = New ConnectionInfo()
    c.ServerName = "####"
    c.DatabaseName = "####"
    c.Password = "####"
    c.UserID = "####"
    c.Type = ConnectionInfoType.SQL
    c.IntegratedSecurity = False

    For i As Integer = 0 To theCrystalReportViewer.LogOnInfo.Count - 1
        theCrystalReportViewer.LogOnInfo(i).ConnectionInfo = c
    Next
0
votes

JGauffin,

Like Lee, I am curious why you'd load a dataset with stored procedure data rather than just pass the credentials to the Crystal Report.

In fact, the code you show doesn't even load a dataset directly anyways. I suggest you have the report pull data directly from the data server using your stored procedure. This just requires that you set credentials to access the server.

If you remove all this code...

Dim c As ConnectionInfo = New ConnectionInfo()
c.ServerName = "####"
c.DatabaseName = "####"
c.Password = "####"
c.UserID = "####"
c.Type = ConnectionInfoType.SQL
c.IntegratedSecurity = False

For i As Integer = 0 To theCrystalReportViewer.LogOnInfo.Count - 1
theCrystalReportViewer.LogOnInfo(i).ConnectionInfo = c
Next

... you can reintroduce this convenience method:

// this line needs you to replace these arguments with the valid values
oReport.SetDatabaseLogon("your", "valid", "settings", "here");

Then, if you only see problems on paging, printing and exporting, you should make sure you keep setting the ReportSource back to the view.

if (!IsPostBack) 
{
// all your existing code should go in here
// this includes the SetDatabaseLogon etc.
// at the right moment, save your oReport in session
Session["myReportDocument"] = oReport;
theCrystalReportViewer.ReportSource = oReport;
}
else // we are posting back, so make sure the viewer still has the report object
{
theCrystalReportViewer.ReportSource = (ReportDocument)Session["myReportDocument"];
}

I hope this gets you on the right path.