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

3.1 call IConnectionInfo.SetConnection( serverName, databaseInstanceName, true) for each one

4. Iterate through each Table object in ReportDocument.Database.Tables

4.1 Create a new ConnectionInfo object and set .ServerName, .DatabaseName, and .IntegratedSecurity

4.2 Assign that object to Table.LogOnInfo.ConnectionInfo

4.3 Call Table.ApplyLogOnInfo( Table.LogOnInfo );

4.4 Assign Table.Location = database + ".dbo." + toApplyTo.Location.Substring( toApplyTo.Location.LastIndexOf( "." ) + 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.VerifyDatabase() *NOTE: THIS NEVER FAILS*
7. Assign CrystalReportViewer.ReportSource = 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):

		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();

		}

Open in new window



Thanks,

-David
dsmelser83Asked:
Who is Participating?
 
mlmccConnect With a Mentor Commented:
This question gets asked over and over again and has no set answer.

The best way to use Crystal is to pass (push) the data to the report through an application dataset.
http://www.emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx

mlmcc
0
 
dsmelser83Author Commented:
Following those steps I get:

+            ex as CrystalDecisions.CrystalReports.Engine.DataSourceException      {"Unknown Query Engine Error\rError in File C:\\DOCUME~1\\dsmelser\\LOCALS~1\\Temp\\integratedSecurityTest {F9137C6F-18EC-45F6-B119-D7D68D15D924}.rpt:\nUnknown Query Engine Error"}      CrystalDecisions.CrystalReports.Engine.DataSourceException


with an inner exception of:

-            ex.InnerException as System.Runtime.InteropServices.COMException      {"Unknown Query Engine Error\rError in File C:\\DOCUME~1\\dsmelser\\LOCALS~1\\Temp\\integratedSecurityTest {F9137C6F-18EC-45F6-B119-D7D68D15D924}.rpt:\nUnknown Query Engine Error"}      System.Runtime.InteropServices.COMException

At least I've got a new error to track down...   :-\
0
 
dsmelser83Author Commented:
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...
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.