Solved

Unable to connect Crystal Report to database on client machine

Posted on 2011-09-13
13
434 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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
 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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