Dynamically redirecting CR report

I'm using C# 4.0 with Crystal Reports. I'm trying to dynamically redirect a report to a designated database using integrated security. Here's the code I'm using:
 public static void SetReportDatabaseSource(string databaseName, string reportName, ReportClass reportClass) {
            // See http://www.businessobjects.com/global/pdf/dev_zone/VS2005_Walkthroughs.pdf, "Logging onto a Secure SQL Server Database Using Integrated Security"
            //  Using embedded report
            // See also http://snippets.dzone.com/posts/show/4029 re use of Table.Location
            // See also http://msdn.microsoft.com/en-us/library/ms227736%28v=VS.80%29.aspx: apparently for integrated security, either leave server name unspecified or else set to ""

            try {
                ConnectionInfo connectionInfo = new ConnectionInfo();
                connectionInfo.DatabaseName = databaseName;
                connectionInfo.IntegratedSecurity = true;
                connectionInfo.ServerName = ""; // server name in this case is STUV3_2Reports ... the odbc connection

                Tables reportTables = reportClass.Database.Tables;
                foreach (Table theTable in reportTables) {
                    TableLogOnInfo theTableLogoninfo = theTable.LogOnInfo;
                    theTableLogoninfo.ConnectionInfo = connectionInfo;
                    theTable.ApplyLogOnInfo(theTableLogoninfo);
                    theTable.Location = connectionInfo.DatabaseName + ".dbo." + theTable.Location;
                }
            }
            catch (Exception ex) {
                MessageBox.Show("Problem redirecting " + reportName + " report\n\n" + ex.ToString());
            }
        }

Open in new window

The code gives me this error:
System.Runtime.InteropServices.COMException (0x800002F4): Failed to open the connection. Failed to open the connection.
temp_c90c99a0-76bb-4baa-9eb8-5b58ffaf4c98 {FCD31F6A-148F-41C5-8809-6F15A88079BF}.rpt 
   at CrystalDecisions.ReportAppServer.Controllers.DatabaseControllerClass.SetTableLocation(ISCRTable CurTable, ISCRTable NewTable) 
   at CrystalDecisions.CrystalReports.Engine.Table.set_Location(String value) 
   at MyPgm.clsGuiGlobalFunctions.SetReportDatabaseSource(String databaseName, String reportName, ReportClass reportClass) in C:\MyPgm\clsGuiGlobalFunctions.cs:line 1287

Open in new window

Any thoughts?
LVL 1
BlearyEyeAsked:
Who is Participating?
 
BlearyEyeAuthor Commented:
Continuing the love/hate relationship with CR ... I moved the project to another machine. The keycode error doesn't occur there, and the redirection works. Presumably if I solve the keycode issue on the original machine, the code will work.

I suppose I should mark this comment as the solution ...



0
 
mlmccCommented:
How do you open the report?

mlmcc
0
 
BlearyEyeAuthor Commented:
private CrystalDecisions.Windows.Forms.CrystalReportViewer crvTreatHistory;
rptTreatmentHistory m_oTreatmentHistoryReport = new rptTreatmentHistory();
(assign parameters)
crvTreatHistory.ParameterFieldInfo = paramFields;
crvTreatHistory.ShowRefreshButton = false;
crvTreatHistory.ShowGroupTreeButton = false;
crvTreatHistory.ReportSource = m_oTreatmentHistoryReport;

Open in new window

0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
mlmccCommented:
Where do you call the set database code?

mlmcc
0
 
BlearyEyeAuthor Commented:
Actually, this might be a false alarm. I just tried opening one of the reports in VS and got a keycode error. I'll see about fixing that first.
0
 
mlmccCommented:
0
 
BlearyEyeAuthor Commented:
That link applies to older versions. CR for VS 2010 does not require a keycode: http://forums.sdn.sap.com/thread.jspa?threadID=1908415. I uninstalled CR on the offending machine and reinstalled it. Now I can open the reports and they are redirected correctly.
0
 
BlearyEyeAuthor Commented:
The original issue turned out to be spurious. Something had gone wrong with my installation of CR. I uninstalled and reinstalled it, and the issue went away.

The presenting issue, invalid keycode, is apparently a typical symptom of a corrupted CR installation for VS 2010, since a keycode is no longer required.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.