[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Cannot load CrystalReportViewer even with good connection information.

Posted on 2011-10-20
3
Medium Priority
?
431 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:dsmelser83
  • 2
3 Comments
 
LVL 101

Accepted Solution

by:
mlmcc earned 2000 total points
ID: 37002166
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
 

Author Comment

by:dsmelser83
ID: 37005746
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
 

Author Comment

by:dsmelser83
ID: 37005789
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question