Change Report Datasource at Runtime ???????

If CRVS is to be used in the development of Visual Studio-based software products, one must be able to dynamically set the report data sources at runtime.

However, I have found no clear way to do this, in either the documentation or on the web.

Say it isn't so !!
TIA, Karl


Answer this question

Change Report Datasource at Runtime ???????

  • Jurgen Willis

    Karl, it ain't so!

    You can, indeed, change the data source at run time. In fact there are numerous articles on the web to support this as well as several walk throughs on both MSDN and BusinessObjects websites.

    My favorit of course is Crystal Reports For Visual Studio 2005 - Data Connectivity Tutorial: Connecting to Object Collections. I am a big fan of object collections as I can pass them around applications and web sites simply.

    When I googled "Crystal Reports" "Data source" runtime it returned 69,100 results... So it ain't so Karl.

    If you give more detail on what you are trying to accomplish I would be happy to give you some sample code.

    Regards,

    Jeff
    DEVSOUTH, Inc.


  • Yun yang

    I don't have time to explain, but this function sets the connection information (server) and then resets the "Location". If you delve into this a bit you'll see how it works, since in your case you only need to edit the Location command and not the connection or database. There is a line in this code that is commented out that changes the database, and I'm assuming it works, though it's just a remnant from development that hasn't been removed yet.

    With this code I'm assuming the new command would need the same parameters as the original (if it has parameters). If you're jogging between commands that have different parameters, that would probably be a more complex undertaking.

    *

    Private Sub SetReportServerCredentials(ByRef rptDoc As ReportDocument)

    'set connection information
    Dim cryTable As CrystalDecisions.CrystalReports.Engine.Table
    Dim cryConnInfo As New CrystalDecisions.Shared.ConnectionInfo
    Dim cryLogonInfo As CrystalDecisions.Shared.TableLogOnInfo

    cryConnInfo.ServerName = strSqlServer
    'cryConnInfo.DatabaseName = "cbase" 'hardcode

    For Each cryTable In rptDoc.Database.Tables
    Try
    cryLogonInfo = cryTable.LogOnInfo
    cryLogonInfo.ConnectionInfo = cryConnInfo
    cryTable.ApplyLogOnInfo(cryLogonInfo)
    cryTable.Location = cryTable.Location.Substring(cryTable.Location.LastIndexOf(".") + 1)
    Catch ex As Exception
    Console.WriteLine(ex.Message)
    End Try
    Next

    End Sub


    *

    Jimme


  • Gilles Muys

    Thanks Jimme, for pointing me towards a solution. Here is what I ended up using, from thread:

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=85770&SiteID=1

    C#:
    CrystalReport1 crReport = new CrystalReport1();
    ConnectionInfo crConInfo = new ConnectionInfo();
    crConInfo.ServerName= "ServerName";
    crConInfo.DatabaseName = "DBname";
    crConInfo.UserID = "UID";
    crConInfo.Password = "PWD";
    TableLogOnInfo crLogInfo = new TableLogOnInfo();
    crLogInfo.ConnectionInfo = crConInfo;
    crReport.Database.Tables[0].ApplyLogOnInfo(crLogInfo);

    Karl

  • Change Report Datasource at Runtime ???????