dsmelser83
asked on
Cannot load CrystalReportViewer even with good connection information.
This is my first attempt at using a CrystalReportViewer control, so please forgive me if I'm making some obvious mistake.
Here are the steps I'm taking to try to populate it with a very simple report (just a couple of fields dragged over). Some of this may be overkill or unnecessary but I've been tearing my hair out trying to figure out what the missing bit of magic is.
1. new the ReportDocument object
2. Call ReportDocument.Load( reportpath.rpt)
3. Iterate through each IConnectionInfo object in ReportDocument.DataSourceC onnections
3.1 call IConnectionInfo.SetConnect ion( serverName, databaseInstanceName, true) for each one
4. Iterate through each Table object in ReportDocument.Database.Ta bles
4.1 Create a new ConnectionInfo object and set .ServerName, .DatabaseName, and .IntegratedSecurity
4.2 Assign that object to Table.LogOnInfo.Connection Info
4.3 Call Table.ApplyLogOnInfo( Table.LogOnInfo );
4.4 Assign Table.Location = database + ".dbo." + toApplyTo.Location.Substri ng( toApplyTo.Location.LastInd exOf( "." ) + 1 );
4.5 Call Table.TestConnectivity *NOTE: THIS NEVER FAILS*
5. Repeat the process for any subreports ( there are none in my test reports)
6. Call ReportDocument.VerifyDatab ase() *NOTE: THIS NEVER FAILS*
7. Assign CrystalReportViewer.Report Source = ReportDocument
The control loads with no data, just as I see it in the designer.
What am I doing wrong?
My code (_workingDb is my database wrapper object in other parts of the application, but here I'm just using it as a container for the relevant information):
Thanks,
-David
Here are the steps I'm taking to try to populate it with a very simple report (just a couple of fields dragged over). Some of this may be overkill or unnecessary but I've been tearing my hair out trying to figure out what the missing bit of magic is.
1. new the ReportDocument object
2. Call ReportDocument.Load( reportpath.rpt)
3. Iterate through each IConnectionInfo object in ReportDocument.DataSourceC
3.1 call IConnectionInfo.SetConnect
4. Iterate through each Table object in ReportDocument.Database.Ta
4.1 Create a new ConnectionInfo object and set .ServerName, .DatabaseName, and .IntegratedSecurity
4.2 Assign that object to Table.LogOnInfo.Connection
4.3 Call Table.ApplyLogOnInfo( Table.LogOnInfo );
4.4 Assign Table.Location = database + ".dbo." + toApplyTo.Location.Substri
4.5 Call Table.TestConnectivity *NOTE: THIS NEVER FAILS*
5. Repeat the process for any subreports ( there are none in my test reports)
6. Call ReportDocument.VerifyDatab
7. Assign CrystalReportViewer.Report
The control loads with no data, just as I see it in the designer.
What am I doing wrong?
My code (_workingDb is my database wrapper object in other parts of the application, but here I'm just using it as a container for the relevant information):
private void FormReport_Load( object sender, EventArgs e )
{
ReportDocument toShow = new ReportDocument();
toShow.Load( _reportPath );
this.Text = toShow.Name;
SetConnectionInfo( toShow, _workingDb.ServerName, _workingDb.DatabaseName );
toShow.VerifyDatabase();
crystalReportViewerMain.ReportSource = toShow;
}
private void SetConnectionInfo( ReportDocument toShow, string server, string database )
{
foreach( IConnectionInfo connInfo in toShow.DataSourceConnections )
{
connInfo.SetConnection( server, database, true );
}
foreach( Table toApplyTo in toShow.Database.Tables )
{
TableLogOnInfo toAlter = toApplyTo.LogOnInfo;
ConnectionInfo newConnection = new ConnectionInfo();
//don't know if this has any impact, fails either way
//newConnection.Type = ConnectionInfoType.SQL;
newConnection.ServerName = server;
newConnection.DatabaseName = database;
newConnection.IntegratedSecurity = true;
//not sure what this does...seems undocumented
//toAlter.ConnectionInfo.AllowCustomConnection = true;
toAlter.ConnectionInfo = newConnection;
toApplyTo.ApplyLogOnInfo( toAlter );
toApplyTo.Location = database + ".dbo." + toApplyTo.Location.Substring( toApplyTo.Location.LastIndexOf( "." ) + 1 );
if( !toApplyTo.TestConnectivity() )
{
MessageBox.Show( "ERROR: could not establish connection to table (" + toApplyTo.Name + ")." );
}
}
foreach( ReportDocument subReport in toShow.Subreports )
{
SetConnectionInfo( subReport, server, database );
}
}
//DEBUGGING SIMPLE STUFF
private void crystalReportViewerMain_DoubleClick( object sender, EventArgs e )
{
crystalReportViewer.Focus();
crystalReportViewer.Refresh();
int pageNum = crystalReportViewer.GetCurrentPageNumber();
crystalReportViewer.Refresh();
crystalReportViewer.InitReportViewer();
crystalReportViewer.Refresh();
crystalReportViewer.PerformAutoScale();
crystalReportViewer.Refresh();
crystalReportViewer.PerformLayout();
crystalReportViewer.Refresh();
crystalReportViewer.Refresh();
crystalReportViewer.Refresh();
crystalReportViewer.RefreshReport();
crystalReportViewer.Refresh();
crystalReportViewer.Show();
crystalReportViewer.Refresh();
crystalReportViewer.ShowFirstPage();
crystalReportViewer.Refresh();
crystalReportViewer.ShowNextPage();
crystalReportViewer.Refresh();
crystalReportViewer.ShowLastPage();
crystalReportViewer.Refresh();
crystalReportViewer.Update();
crystalReportViewer.Refresh();
}
Thanks,
-David
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I followed the advice here to clear that up: http://social.msdn.microsoft.com/Forums/en/vscrystalreports/thread/5ae1b14e-ad6f-4093-baa2-a5d65a8a0bf0 and now I'm back to square one. No exception thrown. No error. Just a blank viewer. Sigh...
ASKER
+ ex as CrystalDecisions.CrystalRe
with an inner exception of:
- ex.InnerException as System.Runtime.InteropServ
At least I've got a new error to track down... :-\