Last post May 23, 2011 03:38 PM by microsoftee
May 23, 2011 10:47 AM|angiemc|LINK
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");
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");
May 23, 2011 03:38 PM|microsoftee|LINK
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