cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to connect report to database on client machine

Former Member
0 Kudos

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

}

}

}

}

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hello,

Install the MS SQL Server Client tools on your PC and when setting location use the MS SQL Native 10 client as your database driver.

Only one MS supports for Server 2008, there is a MS Kbase on this, you can't use MDAC version of the SQL Client engine.

Then update your app to use RAS and search in this forum on ReplaceConnection_click and you'll find my sample code on how to set location to use the new DB server and connection properties.

If that doesn't work then try hard coding the log on info rather than using variables. At the same time, unfortunately SQL Express doesn't have the Management Console, you want to watch the server using Profiler to see what your app is actually sending to the Server. If you have a full version of SQL 2008 then you can monitor what is going on. If not then you'll ahve to find some other tool you can use.

Try ODBC, you can enable ODBC Trace to see is all other options are not available.

If that doesn't work post to MS's forum and ask them why you connection info isn't working.

Thank you

Don

Answers (0)