Skip to Content
0
Former Member
Sep 13, 2011 at 07:58 PM

Unable to connect report to database on client machine

35 Views

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

}

}

}

}