Are you using a .NET dataset or does your report connect to the database?
If you're using a .NET dataset, you need to make sure that you set the datasource of the report to point to the current instance of the dataset prior to setting the reportsource of the viewer. I don't work in VB.NET, but in C# I usually overload the creator of the viewer form so that the form that generates the data can pass the dataset to the viewer. I then create the report object, set its dataset, and then set the reportsource of the viewer. The code looks something like this:
public CrystalDocReportViewer(DataSet ds)
{
InitializeComponent();
rpt = new CrystalDocReport();
rpt.SetDataSource(ds);
viewer.ReportSource = rpt;
}
If you're not using a dataset, but connecting the report to the database, then you have to set the login values when you run the report. We do it this way:
CrystalDecisions.Shared.ConnectionInfo connectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
connectionInfo.ServerName = qServer;
connectionInfo.UserID = rptUserID;
connectionInfo.Password = rptPassword;
// set report connection for main report
Tables tables = crReport.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
}
// set report connection for any subreports
Sections sections = crReport.ReportDefinition.Sections;
foreach (Section section in sections)
{
ReportObjects reportObjects = section.ReportObjects;
foreach (ReportObject reportObject in reportObjects)
{
if (reportObject.Kind == ReportObjectKind.SubreportObject)
{
SubreportObject subreportObject = (SubreportObject)reportObject;
ReportDocument subReportDocument =
subreportObject.OpenSubreport(subreportObject.SubreportName);
tables = subReportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
}
}
}
}
-Dell