Site Search:
Sign in | Join | Help
4Penny.net

Crystal Reports

Notes, Tips and Tricks on Developing using Crystal Reports

June 2007 - Posts

  • Dynamically changing the data source of a Crystal Report at run time

    This is a copy of a post off of the Microsoft forums that I didn't want to lose.

     

    I have the problem about change database name and server name runtime...

    I use CR for VS.NET 2005 to make a simple report
    Use OLEDB for SQL Server and write SQL Statement in COMMAND OBJECT..
    (Error will not occur, if I choose link table, not manually write SQL Statement)
    I found that i cannot change DBName and ServerName

    I receive error when i call function
    Report.Database.Table(i).ApplyLogOnInfo(NewLogOnInfo)
    --------------------------------------------
    Failed to load database information.
    Details: The database DLL 'crdb_query.dll' could not be loaded.
    Error in File C:\DOCUME~1\anop3\LOCALS~1\Temp\{68D71403-5484-4650-B960-D55DB2523564}.rpt:
    Failed to load database information.
    ---------------------------------------------

    Then, I write code in miss password for bring popup, "Select Database" Window, to show
    I found that if I write SQL Statement,
    The Combo box of ServerName and Database are disable
    I can change only userID and Password

    Then I found new function in CR For VS2005
    Report.SetDatabaseLogon()
    It isn't show error but it not work to bring data from new database

    By the way, it correct if i change only userID and Password

    So, I back to try with VS2003... It is OK....

    I don't sure i found it have hotfix for this problem in Crystal Version 10 but not Fix For "Crystal Report for .NET 2005"....
    How can I apply the fix?

    Please Help me to find out what should i missing and
    what should i do

    I think it is the critical function because
    When i develop i use Develop Server and
    I need to change database to Production Server
    and it can done in VS2003


    ==================

     Hello,

    I tried out what you are doing and reproduced the error.  I will track this with our developers.

    At this time we don't have a fix or workaround for this.

    Keith - Business Objects

    ==================

     Command objects were not supported in VS .NET 2003, so how did you design your VS .NET 2003 report?  They were introduced in Crystal Reports 10, so they are new to the Visual Studio releases.

    Unfortunately, I suspect that changing the database server name and database name on Command objects may require crdb_query.dll, which we cut from Crystal Reports for VS 2005.  I will look into this.

    Thanks,

    Francis

    =============================

    OK - I think Ive got it. I was having the same problem as everyone else after updating from vs2003 to vs2005. The same code which worked in 2003 did not work in 2005.

     

    The problem only arises when you run the report on a different database to the one you develop on.

     

    Previously in VS2003, table.Location would report "DATABASE.dbo.NAME"  - and it was possible to use this to change the Location, but in vs2005 table.Location only reports back the NAME.  See below for a fix.

     

    The problem is in this line:

     

    table.Location = connectionInfo.DatabaseName & ".dbo." & _

                                     table.Location.Substring(table.Location.LastIndexOf(".") + 1)

     

    Change it to:

     

    table.Location = connectionInfo.DatabaseName & ".dbo." & table.Name

     

     

    This worked for me. Note that id you use

    table.Location = connectionInfo.DatabaseName & ".dbo." & table.Location then it does not work.

     

    I cant beleive how bad this is, and that CR/Business Objects have not provided a fix for this.

     

    Adam

     

     

  • Running totals in Crystal Reports, the hard way

    I happens that I need to do a running total in a report, and I can't use the built in 'running total' feature for some reason or another. (the current issue is that I need a running total on a formula field that exists only in a group footer)

    The code to do the deed is kind of a pain, but here it is.

     Create a formula called @reset, like this:
    WhilePrintingRecords;
        numbervar total := 0;

    Place this in the Report Header section

    Create a formula called @calc, like this:
    WhilePrintingRecords;
        numbervar total;
        total := total + {@myfieldname};

    Place this in the Group Footer (in my case)

    Create a formula called @print, like this:
    WhilePrintingRecords;
        numbervar total;
        total := total ;

    Place this in the Report Footer.

    @reset is always invisible, and @calc is usually invisible. I mainly only us @print

     

    As always, your comments are welcome