Unable to connect Crystal Report to database on client machine

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



}
}
 
 

WDM_JohnAsked:
Who is Participating?
 
WDM_JohnConnect With a Mentor Author Commented:
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
 
mlmccCommented:
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
 
WDM_JohnAuthor Commented:
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
ajaytempCommented:
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
 
WDM_JohnAuthor Commented:
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
 
mlmccCommented:
WHat code do you use to set the connection information?

mlmcc
0
 
WDM_JohnAuthor Commented:
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
 
ajaytempCommented:
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
 
WDM_JohnAuthor Commented:
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
 
ajaytempCommented:
"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
 
WDM_JohnAuthor Commented:
I eventually discovered the answer myself.
0
 
ajaytempCommented:
See, I told you it was your connection string.   USE .\SQLEXPRESS.  This is in MSDN documentation and on forums everywhere.
0
 
ajaytempCommented:
"and the connection string has 20 parameters that are difficult to match."
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.