Solved

Unable to connect Crystal Report to database on client machine

Posted on 2011-09-13
13
432 Views
Last Modified: 2012-05-12
I am using C# and Visual Studio 2010 with several Crystal Reports embedded into my application as resources. This is a Windows application running on Vista. I am trying to connect to a SQL Server database. I created the reports using the design wizard in VS. I am allowing for the server and database name to be changed at runtime through values stored in the project manifest.

As experienced by hundreds of other frustrated developers, my reports run fine on my development machine but fail on my client machine. On the client machine I am prompted with a database login window. The server name is properly populated with the server name pulled from the ...exe.config file. The database name is blank and the field is disabled. The integrated security checkbox is not checked. I am programatically providing the server name, the database name and specifying integrated security to be true using sample code I found on this forum. See below.

I reviewed the Troubleshooting Guide to Database Connectivity Issue with Crystal Reports in Visual Studio .NET Applications. Accordingly, I am running the SP1 for Visual Studio 2010 on my development machine and the most recent runtime module on the client machine.

Here is my application code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine; //jp
using CrystalDecisions.Shared; //jp

namespace WindowsFormsApplication1
{
public partial class FormRptArtist : Form
{
private CrystalReport1 crReportDocument = new CrystalReport1();


public FormRptArtist()
{
InitializeComponent();
}

private void FormRptArtist_Load(object sender, EventArgs e)
{
try
{
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.IntegratedSecurity = true;
connectionInfo.ServerName = Properties.Settings.Default.CrystalServer; // SQLExpress
connectionInfo.DatabaseName = Properties.Settings.Default.CrystalDatabase; // TriviaProd
SetDBLogonForReport(connectionInfo, crReportDocument);
SetDBLogonForSubreports(connectionInfo, crReportDocument);
crystalReportViewer1.ReportSource = crReportDocument;
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);

}


}

private void SetDBLogonForSubreports(ConnectionInfo connectionInfo, ReportDocument reportDocument)
{
Sections sections = reportDocument.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);
SetDBLogonForReport(connectionInfo, subReportDocument);
}
}
}
}


private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
{
Tables tables = reportDocument.Database.Tables;

foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
}
}



}
}
 
 

0
Comment
Question by:WDM_John
  • 6
  • 5
  • 2
13 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 36533013
As you have seen this is a widely asked question.  I have never found an answer that works for everyone.  Each case seems to be unique.  That said, my recommendation is to push the data to the report.

The push method uses a dataset built in the application then passed to the report.  In that way the application handles the database work and the report just uses the data.

Here is one method

http://www.emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx

mlmcc
0
 

Author Comment

by:WDM_John
ID: 36533250
Thank you for the example for pushing data to my report.  I may consider this as a last resort but am still hoping to solve my problem by curing the connection problem and allow my report to pull data directly from the database.
0
 

Expert Comment

by:ajaytemp
ID: 36538438
private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
{
Tables tables = reportDocument.Database.Tables;

foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
}
}

Open in new window


Is rptDoc database objects' table object logon info up to date ?
0
 

Author Comment

by:WDM_John
ID: 36538549
Yes, the logon info is up to date.  The server name provided is "SQLExpress" and the database name is "TriviaProd".  These are the correct names unless some additional qualification is required.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 36539342
WHat code do you use to set the connection information?

mlmcc
0
 

Author Comment

by:WDM_John
ID: 36539429
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.IntegratedSecurity = true;
connectionInfo.ServerName = Properties.Settings.Default.CrystalServer; // SQLExpress
connectionInfo.DatabaseName = Properties.Settings.Default.CrystalDatabase; // TriviaProd

What is unusual is that it appears to be receiving the server name okay because it is filled in when the database login prompt is displayed.  However, the database field is blank and is not enabled so it does not appear to be receiving my database assignment.  Also, the integrated security checkbox is not checked even though I set it to true with the command above.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Expert Comment

by:ajaytemp
ID: 36539911
well, db admins can put permissions on pretty much any object in the database for security.  and the connection string has 20 parameters that are difficult to match.
0
 

Author Comment

by:WDM_John
ID: 36540239
This is a single user application on a stand-alone PC.  I installed the database and can connect to it from my application.  It's only the Crystal Reports that can't seem to connect.
0
 

Expert Comment

by:ajaytemp
ID: 36540591
"These are the correct names unless some additional qualification is required."

Readers here would not know what.  First, post your actual connection string CR is using if you know how.  And then compare it to the other application you state is working.
0
 

Accepted Solution

by:
WDM_John earned 0 total points
ID: 36557219
As it turns out there were two contributing issues.
1) I had to create a new datasource for the report and reassociate the report tables to it using the update function.  (OLE DB (ADO) with provider SQLOLEDB).  
2) The server name I specified at runtime, SQLExpress, had to be referred to as .\SQLExpress.

The following link was most helpful in resolving this issue.
http://msdn.microsoft.com/en-US/library/ms227768(v=VS.80).aspx
0
 

Author Closing Comment

by:WDM_John
ID: 36585519
I eventually discovered the answer myself.
0
 

Expert Comment

by:ajaytemp
ID: 36587522
See, I told you it was your connection string.   USE .\SQLEXPRESS.  This is in MSDN documentation and on forums everywhere.
0
 

Expert Comment

by:ajaytemp
ID: 36587550
"and the connection string has 20 parameters that are difficult to match."
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now