Solved

Refreshing Crystal Reports using a vb.net console application.

Posted on 2004-03-31
6
1,704 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

726 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