Changing Datasource at runtime [UNRESOLVED] RRS feed

  • Question

  • THe following applies to Crystal Reports for Visual Studio 2005 v10.2.3600.0

    When I change the datasource of a report at runtime to anything other than my development machine, I am getting the following errors...

    "The field name is not known."
    "Error in File..."
    "Error in formula <Monday>"
    This field name is not known

    Note: **This paramter is created from the stored procedure used to create the report

    Failed to open a rowset, procedure expects parameter @LocationID which was not supplied.

    Note: **the parameter is supplied during runtime


    I have reproduced the following several times.

    1. Created a report that gets data from a stored procedure having
    parameters on sql server

    2. create a vb.net project with a crystalreportviewer control

    3. bind the report to the control at runtime

    4. at runtime, the viewer control will ask the user to input values for
    the params

    5. report loads as expected

    During step 3, if the database location is changed to a different
    server than the one used when developing the Crystal Report, the
    following will occur.

    -->4. at runtime, the viewer control will ask the user to input values
    for the params

    -->5. report loading fails with an ADO error stating the stored
    procedure expected parameters that were not supplied.

    This works backwards as well, meaning I then create a report using the production server, then change the datasource at runtime to my dev machine which gets the same results as above.

    Wednesday, November 22, 2006 10:28 PM

All replies

  • I added the following code after reading some posts...



    Catch ex As Exception


    End Try

    This traps a logon error...  I have tried the following code to set the datasource

    rpt.DataSourceConnections.Item(0).SetConnection(conn.DataSource, conn.Database, False)

    rpt.DataSourceConnections.Item(0).SetLogon(user, pass)


    Dim conns As DataSourceConnections = rpt.DataSourceConnections

    Dim info As IConnectionInfo = conns(0)

    info.SetConnection(conn.DataSource, conn.Database, user, pass)


    'Set the db logon info

    With crConnectionInfo

    .ServerName = conn.DataSource

    .DatabaseName = conn.Database

    .UserID = user

    .Password = pass

    End With

    'Loop through each table in the report and apply the LogonInfo information

    Dim CrTables As Tables = rpt.Database.Tables

    For Each CrTable As Table In CrTables

    crtableLogoninfo = CrTable.LogOnInfo

    crtableLogoninfo.ConnectionInfo = crConnectionInfo




    Wednesday, November 22, 2006 10:37 PM
  • Anyone with any ideas?
    Friday, November 24, 2006 5:13 PM
  • Is it possible that there is a slight difference in the stored procedures between the two servers.  Different capitalization, data type, etc.
    Friday, November 24, 2006 7:45 PM
  • Unfortunatly not.  I have several vs2003 projects that run fine, its only my vs2005 projects that i have a problem with.
    Monday, November 27, 2006 2:19 PM
  • Hi,

    Just had the same problem in VS2005. I managed to solve it with the following code:

                              Report.Database.Tables[1].Location = "Name_SP;1";

    So basically, after applying the new logoninfo, you have to set the table location again so it removes the old server name from it.



    Wednesday, December 20, 2006 10:37 AM
  • I solved this by installing the Crystal Reports hotfix for Crystal Reports.NET

    KBase Article ID=c2018840

    Or, just download hotfix from
    • Proposed as answer by Catalin Andrei Wednesday, June 11, 2008 12:26 PM
    Tuesday, January 9, 2007 5:23 PM
  • Dim crReportDocument As New ReportDocument

    Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table

    Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo

    For Each tbCurrent In crReportDocument.Database.Tables

    tliCurrent = tbCurrent.LogOnInfo

    With tliCurrent.ConnectionInfo

    .ServerName = gServer

    .DatabaseName = gDataBaseShr

    .UserID = gUsername

    .Password = gPassword

    End With



    'Conectar a la base de datos correcta



    Dim sLocation As String = tbCurrent.Location.ToString()

    Dim iposPunto As Integer = sLocation.IndexOf(".")

    sLocation = Convert.ToString(gDataBaseShr & ".dbo." & sLocation.Substring(iposPunto + 1))

    tbCurrent.Location = sLocation

    Next tbCurrent

    Thursday, February 1, 2007 9:01 PM
  • Thank you Glantzie!  I'll have to put you on my Heroes list.

    And no thanks to anyone involved in the development of Crystal Reports.  There is no good excuse for the dozens of problems that Crystal Reports has and continues to have, version after version after version.  Only a poorly-run company would allow such a marketable product to continue with such poor quality.  Fortunately, Microsoft's reporting product is currently a close second as far as competitive features go, so it won't be long before the Crystal company (currently Business Objects?) is sueing Microsoft for putting them out of business by creating a superior product.


    Monday, March 19, 2007 11:13 PM
  • I was download hotfix from

    I try to run again, the error not fine again in my PC ( Source Program )..

    I Has build,publish dan install setup in client PC
    But in computer client still error...

    Wednesday, March 21, 2007 7:48 AM
  • I too owe Glantzie big time on this one.  I did a ton of searching on this issue, but this was the first suggestion that worked!! 

    Wednesday, June 13, 2007 2:25 AM
  • The hotfix fixed this issue for me. Thanks a lot "OLD PROFILE"   :-)

    Wednesday, June 24, 2009 9:13 PM
  • To all,

    Here are the stupid codes to change the datasource at runtime,

    foreach ( CrystalDecisions.Shared.IConnectionInfo conInfo in report.DataSourceConnections)
    conInfo.SetConnection("servername", "database", "username" , "password");

    // this is the wierd code I've ever seen but it work. you need to re-assign the value to itself. Amazing hehehe
    foreach(Table tb in report.Database.Tables)
    string tLoc = tb.Location;
    tb.Location = tLoc;

    Monday, October 12, 2009 5:04 PM