Solved

Refreshing Crystal Reports using a vb.net console application.

Posted on 2004-03-31
6
1,692 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

786 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