views:

708

answers:

2

I'm working on an existing report and I would like to test it with the database. The problem is that the catalog set during the initial report creation no longer exists. I just need to change the catalog parameter to a new database. The report is using a stored proc for its data. It looks like if try and remove the proc to re-add it all the fields on the report will disapear and I'll have to start over.

I'm working in the designer in Studio and just need to tweak the catalog property to get a preview. I have code working to handle things properly from the program.

A: 

EDIT: Saw your edit, so i'll keep my original post but have to say.. I've never had a crystal report in design mode in VS so I can't be of much help there sorry.

report.SetDatabaseLogon(UserID, Password, ServerName, DatabaseName);

After that you have to roll through all referenced tables in the report and recurse through subreports and reset their logoninfo to one based on the reports connectioninfo.

 private void FixDatabase(ReportDocument report)
 {
  ConnectionInfo crystalConnectionInfo = someConnectionInfo;

  foreach (Table table in report.Database.Tables)
  {
   TableLogOnInfo logOnInfo = table.LogOnInfo;

   if (logOnInfo != null)
   {
    logOnInfo.ConnectionInfo = crystalConnectionInfo;

    table.LogOnInfo.TableName = table.Name;
    table.LogOnInfo.ConnectionInfo.UserID = someConnectionInfo.UserID;
    table.LogOnInfo.ConnectionInfo.Password = someConnectionInfo.Password;
    table.LogOnInfo.ConnectionInfo.DatabaseName = someConnectionInfo.DatabaseName;
    table.LogOnInfo.ConnectionInfo.ServerName = someConnectionInfo.ServerName;
    table.ApplyLogOnInfo(table.LogOnInfo);

    table.Location = someConnectionInfo.DatabaseName + ".dbo." + table.Name;
   }
  }

  //call this method recursively for each subreport
  foreach (ReportObject reportObject in report.ReportDefinition.ReportObjects)
  {
   if (reportObject.Kind == ReportObjectKind.SubreportObject)
   {
    this.FixDatabase(report.OpenSubreport(((SubreportObject)reportObject).SubreportName));
   }
  }
 }
Quintin Robinson
+1  A: 

If you just need to do it in the designer then right click in some whitespace and click on Database->set datasource location. From there you can use a current connection or add a new connection. Set a new connection using the new catalog. Then click on your current connection in the top section and click update. Your data source will change. But if you need to do this at runtime then the following code is the best manner.

#'SET REPORT CONNECTION INFO
        For i = 0 To rsource.ReportDocument.DataSourceConnections.Count - 1
            rsource.ReportDocument.DataSourceConnections(i).SetConnection(crystalServer, crystalDB, crystalUser, crystalPassword)
        Next
Jas