?
Solved

Refreshing Crystal Reports using a vb.net console application.

Posted on 2004-03-31
6
Medium Priority
?
1,712 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

800 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