thesierras
Programmer
I'm using C# in Visual Studio 2010 to create an interface that displays Crystal Reports already generated in 8.5 and 9.0. The reports are all based upon result sets returned from stored procedures in SQL Server 2008. Most of the stored procedures accept parameters, but I chose an example without parameters to try to simplifiy this issue. We have multiple client databases across multiple servers, but the structure of the data and the stored procedure names are consistant across the client databases. Through our legacy front end (written in Visual FoxPro) we simply change the server name, database name, user name and password and the reports run correctly across the appropriate client's data. I'm having a problem getting C# to work in that same way.
This particular example is to run a sepcific report for a specific client database. You'll see in the code that I have two different reports that I have tested. When I use the RPT that runs across a table, it works correctly, but when I run the RPT that runs across a SP, I get "The table 'MyStoredProcedure' could not be found...". Both have been tested directly through CR and work fine. Any Suggestions?
Code:
:
:
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
:
:
private void button1_Click(object sender, EventArgs e)
{
ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables ;
//// Table - Local_Clients
cryRpt.Load("C:\\CRTestWithTable.rpt");
//// Stored Procedure - Database Integrity
// cryRpt.Load("C:\\CRTestWithSP.rpt");
crConnectionInfo.ServerName = "MYSERVERNAME";
crConnectionInfo.DatabaseName = "MYDBNAME";
crConnectionInfo.UserID = "MYUSERNAME";
crConnectionInfo.Password = "MYPASSWORD";
CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
}
:
: