Let's see how we can log into the report automatically.
First we need to add a button that we will use to automatically log in using
the Crystal Report Document object. The next section we will use the log on
setting option in the Crystal Viewer.
First, let's drag a button over on the form. Drag over a
button from the Toolbox, Windows forms. It should look similar to Figure 1.
The above figure also contains the button called "Logon
Viewer" which we will talk through in the next section. In the following
Burndown rptBurndown = new Burndown();
CrystalDecisions.Shared.ConnectionInfo crDbConnection = new
crDbConnection.IntegratedSecurity = true;
crDbConnection.DatabaseName = "TfsWorkItemTracking";
crDbConnection.ServerName = "tfdbserver";
CrystalDecisions.CrystalReports.Engine.Database crDatabase =
foreach (CrystalDecisions.CrystalReports.Engine.Table oCrTable in
oCrTableLoginInfo = oCrTable.LogOnInfo;
oCrTableLoginInfo.ConnectionInfo = crDbConnection;
crystalReportViewer1.ReportSource = rptBurndown;
In this code, we are able to log onto a report document.
First we create a new instance of the Burndown report. We create a new
ConnectionInfo object, for this instance just one will do. If you would ever
need to log onto different sources, then you need to make multiple
connectioninfo objects. We then get a Database object from the Burndown report
Finally we loop through all the tables in the reports
database.tables collection. First getting TableLoginInfo objects from the
report database, we set the connectioninfo property of that object to the
database connection info set earlier. Here is where you would need to make
changes if you are logging into multiple data sources.