Solved

Refreshing Crystal Reports using a vb.net console application.

Posted on 2004-03-31
6
1,695 Views
Last Modified: 2010-08-05
 I am looking for a way to refresh a crystal report(8.0) .rpt file using a vb.net console application. I also want to save that refreshed data. Currently if you run this .rpt manually you get prompted for a database login, which I want to handle in the app as well.  I have been playing with this but have been unable to get everything to work.
  Here is what I have so far:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Module Module1
    Private reportDocument1 As CrystalDecisions.CrystalReports.Engine.ReportDocument

    Sub Main()
        reportDocument1 = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
        reportDocument1.Load("c:\test1.rpt")

        Dim logonInfo As TableLogOnInfo = New TableLogOnInfo()
        logonInfo = reportDocument1.Database.Tables(0).LogOnInfo
        logonInfo.ConnectionInfo.ServerName = "g"
        logonInfo.ConnectionInfo.DatabaseName = "accounts"
        logonInfo.ConnectionInfo.UserID = "sa"
        logonInfo.ConnectionInfo.Password = "sa"
        reportDocument1.Database.Tables(0).ApplyLogOnInfo(logonInfo)
        reportDocument1.Refresh()
    End Sub

End Module

  This doesn't appear to be actually refreshing my report. I am new to using crystal reports so I am sure I am missing a key concept here.

Chris ...
0
Comment
Question by:cwigley
6 Comments
 
LVL 2

Expert Comment

by:DonRameshSachin
ID: 10729718
Hi,
 In the report viewer itself there will be a refresh button available. U can use that button to refresh the report and whatever changes made in the database will get relected in the report viewer.

Don
0
 

Author Comment

by:cwigley
ID: 10731417
Don,

  I am looking to do this without user interaction. This is to be an automated process from start to finish. Is it possible to call this same functionality from the viewer, through code?

Chris
0
 
LVL 27

Expert Comment

by:planocz
ID: 10731676
Hi cwigley,

'Use for Logins.............

Imports System.Data.SqlClient
Imports System.Windows.Forms
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.Shared

'use as global Vars.
    Public myReport As New ReportDocument        'Gobal Report Doc
    Public sReportName As String                 'Crystal Report Name from list
    Public sReportPath  as String                  'Path for your reports to load
    '**** Server Connection Vars *********
    Public sDBServer As String = "MyServer"
    Public sUSERid As String = "UserID"
    Public sDBName As String = "DBName"
    Public sDBPass As String = "APassword"
    Public Connect As SqlConnection                  'Use for msSQL
    Public SyConnect As Odbc.OdbcConnection   'Use for Sybase dbases
    Public sSQL As String

 Private Sub GetReportConnection(ByVal myReport)
        ' Objects used to set the proper database connection information
        Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
        Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo

        Try
            ' Load the report
            myReport.Load(sReportPath & sReportName, CrystalDecisions.[Shared].OpenReportMethod.OpenReportByTempCopy)

            ' Set the connection information for all the tables used in the report
            For Each tbCurrent In myReport.Database.Tables
                tliCurrent = tbCurrent.LogOnInfo
                With tliCurrent.ConnectionInfo
                    .ServerName = sDBServer
                    .UserID = sUSERid
                    .Password = ""
                    .DatabaseName = sDBName
                End With
                tbCurrent.ApplyLogOnInfo(tliCurrent)
            Next tbCurrent
        Catch Exp As LoadSaveReportException
            MsgBox("Incorrect path for loading report.", _
                    MsgBoxStyle.Critical, "Load Report Error")
        Catch Exp As Exception
            MsgBox(Exp.Message & "   in GetReportConnection Procedure", MsgBoxStyle.Critical, "General Error")
        End Try
    End Sub
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

Author Comment

by:cwigley
ID: 10735903
Planocz,

  Your code does about the same thing that mine already does. It still does not get me to the point of actually refreshing and saving this report. That is the part that I am stuck with.
0
 
LVL 13

Accepted Solution

by:
EwaldL earned 125 total points
ID: 10736421
saving a report is done by exporting, ie with .net 2003
Dim rpt As New ReportDocument rpt.Load("c:\\yourreport.rpt");
rpt.ExportToDisk(ExportFormatType.PortableDocFormat, "c:\export\yourreport.pdf")
(from http://support.businessobjects.com/library/kbase/articles/c2013529.asp)

or .net 2002
http://support.businessobjects.com/library/kbase/articles/c2010264.asp

you can chose different file types, such as .rpt, .pdf, .doc or others. the available options depends on whether you are also using the full crystal reports 9 or 10 (developer or advanced edition)
0
 

Author Comment

by:cwigley
ID: 10736503
Ewaldl,

  Thank you. That is exactly what I was looking for!

Chris
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question