Error when specifying a different connection string to the one saved in the Crystal Repor RRS feed

  • Question

  • User407913834 posted


    I've created my Crystal Report and in doing so I used the Database Export to create a command so that I could design and preview. In my ASP page I need to specify the actual database connection based on my web.config connection string so I'm using SetDatabaseLogon. If this is the same connection as the connection saved in the rpt file this all works fine, however as soon as I change my connection string in web.config it doesn't work and I have to open the .rpt file and save it with the same connection string. Obviously this is not ideal! Can someone please let me know how to get around this? The error that I get is the usual vague "Unable to connect: incorrect log on parameters.". My code is below. Thanks! Angie


    ReportDocument repDoc = new ReportDocument();
    string path = Server.MapPath("myPath");
    repDoc.SetParameterValue(0, Identity);
    Response.Buffer = false;
     SqlConnectionStringBuilder decoder = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["myConnStr"].ConnectionString);
    repDoc.SetDatabaseLogon(decoder.UserID, decoder.Password, decoder.DataSource, decoder.InitialCatalog);
    repDoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Invoice");

    Monday, May 23, 2011 10:47 AM


  • User2101661063 posted




    Drop a ReportSource control to form and set CrystalReportSource control's report file .rpt and set DataSources to SQLDataSource control, set SQLDataSource control commandText to your query. This way you can any connection to any database dynamically.

    This is how I deal with it, more details about ReportSource control at MSDN


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 23, 2011 3:38 PM