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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
mlmccCommented:
Where do you call the set database code?

mlmcc
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.