Can't view Crystal Report

T

Terren

Hi

I am trying to view a Crystal report (8.5) using the Crystalreports
viewer for C#.net.

I have a form and the view control on it. I am using the following
code to try load the report as the database location might change from
PC to PC. The report is using a Microsoft Access Database. There is no
chance of me changing to Sql Server or another Database. I even remove
the database password but it keeps asking for the password and
username, even though I re-enter the corret information

ReportDocument crRpt = new ReportDocument();
crRpt.Load(Application.StartupPath + @"\Reports
\MyRpt.rpt");

TableLogOnInfo logOnInfo = new TableLogOnInfo();

for (int i = 0; i < crRpt.Database.Tables.Count; i++)
{
// Set the connection information for the current
table.
logOnInfo.ConnectionInfo.AllowCustomConnection=true;
logOnInfo.ConnectionInfo.Type =
ConnectionInfoType.DBFile;
logOnInfo.ConnectionInfo.IntegratedSecurity = false;
logOnInfo.ConnectionInfo.ServerName = "MS Access
Database";
logOnInfo.ConnectionInfo.DatabaseName =
Application.StartupPath + @"\myDatabase.mdb";
logOnInfo.ConnectionInfo.UserID = "admin";
logOnInfo.ConnectionInfo.Password = "password";
crRpt.Database.Tables.ApplyLogOnInfo(logOnInfo);
}


Any help would be appreciated
 
T

TheSteph

Hi !

You probably have to Add this line after the "For...{}" :
crRpt.VerifyDatabase();

I dont know exactly how it works with Access Db, but you may have to change
crRpt.Database.Tables.Location for each table. (With SQL server I had to
change it to "DATABASE_NAME.dbo.TABLE_NAME";

If you have Subreports in your reports, you have to change the Logoninfo for
each table from each sub-report, but you have to do it BEFORE changing the
logoninfo of the main report.

Steph.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top