Crystal Report woes

thirteentwenty

Well-known member
Joined
Oct 9, 2008
Messages
80
Location
Honolulu
Programming Experience
Beginner
Hey there gang...

I've been trying to put together some reports with Crystal Reports and all goes fine until I try to compile/package. The reports pull (or try to) the data from the test database. After much googling and muddling around with it I've gotten it to work, kind of... but after a few report views it throws an exception. Anyways, if anyone can help with that it'd be cool...

What I really come to ask is for an alternitive... what in your opinions would be a better choice of report?
 
OK so I've gotten most of the issues hammered out... for some reason when uninstalling the app it would un-register the CR dlls... easy fix... but there still is the issue of why its trying to get data from the wrong database... so now its a matter of figuring out how to change the datasource programmatically, I've found several articles on how to do so but they don't offer much in the way of flexibility (meaning I don't want to have to create a report viewer and the mess of code to change the database for each of the reports that I need to run).

But the question at hand, finding a suitable replacement for CR still stands... I did find this post mentioning DevExpress and Data Dynamics as alternatives... so to you VB.NET community I ask what are your opinions on these?
 
Hi,
I had used the following code snippet for changing the database connection. Try this and hope this helps you.

VB.NET:
ReportDocument reportDocument = new ReportDocument();
        reportDocument.Load("Path to your *.rpt file");
CrystalDecisions.Shared.ConnectionInfo connectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
        connectionInfo.ServerName = " Your database server name";
        connectionInfo.DatabaseName = "Your database name";
        connectionInfo.UserID = "Your database user name";
        connectionInfo.Password = "Your database password";
        CrystalDecisions.CrystalReports.Engine.Tables tables = reportDocument.Database.Tables;
        foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
        {
            CrystalDecisions.Shared.TableLogOnInfo tableLogOnInfo = table.LogOnInfo;
            tableLogOnInfo.ConnectionInfo = connectionInfo;
            table.ApplyLogOnInfo(tableLogOnInfo);
        }
        reportDocument.VerifyDatabase();
 
Hi,
I had used the following code snippet for changing the database connection. Try this and hope this helps you.

Hey there ajeeshco

Thanks for the reply, I noticed in your code that there is a call for the server name, the database will be on the local machine as this will be a standalone application. Would I use "localhost" or the like? In any case I'll play around with the code and post back here if I can get it to work or if I run into any major issues...

Thanks again!
 
it is a very complex for.. you can use ado.net ->tables to design reports and
in button command type:
VB.NET:
Dim Nrpt as New ReportObject
Nrpt.Database.Tables(0).SetDataSource(dataset) 'dataset where you fill     'datatables
 
Hey there ajeeshco, thanks for the point in the right direction... it took me a wee bit to get back to this project and take a look at it... but in the end your code (with some minor modifications) worked like a charm... below is what I ended up using

VB.NET:
    Dim table As CrystalDecisions.CrystalReports.Engine.Table
    Dim tableLogOnInfo
    Dim tables
    Dim conInfo As New CrystalDecisions.Shared.ConnectionInfo
    Dim rptDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument

    Private Sub crv_reportViewer_viewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles crv_reportViewer_viewer.Load
        Dim conInfo As New CrystalDecisions.Shared.ConnectionInfo
        Dim strReportPath As String = My.Application.Info.DirectoryPath & "\" & strReportName & ".rpt"
        Try
            conInfo.IntegratedSecurity = False

            conInfo.DatabaseName = My.Application.Info.DirectoryPath & "\" & "stupidDB.mdb"
            rptDocument.Load(strReportPath)
            tables = rptDocument.Database.Tables
            For Each table In tables
                tableLogOnInfo = table.LogOnInfo
                tableLogOnInfo.ConnectionInfo = conInfo
                table.ApplyLogOnInfo(tableLogOnInfo)
            Next
            rptDocument.VerifyDatabase()
            rptDocument.ReportOptions.EnableSaveDataWithReport = False
            Me.crv_reportViewer_viewer.ReportSource = rptDocument
        Catch ex As Exception
            MessageBox.Show(ex.Message & vbCrLf & ex.ToString)
        End Try

    End Sub

I guess you had dropped some C# in there so it confused me a bit... but in the end it all worked out just fine.

I wrapped it in a try/catch because initially when getting things sorted out it was throwing an innerException error, I can't recall the _exact_ nature of the message but it did have to do with the location of the mdb file. once I got everything sorted out BINGO...

Thanks again

@alim :: I'm sure your solution would have worked fine, and I would have tried to use it had I not made progress with ajeeshcos suggestion. I did find your suggestion a bit vague so I would have had more questions... In any case thanks for chiming in... its always appreciated!
 
Back
Top