Print Page | Close Window

asking every time username password

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005-2015
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=4893
Printed Date: 01 Dec 2020 at 1:00pm


Topic: asking every time username password
Posted By: adnan
Subject: asking every time username password
Date Posted: 28 Nov 2008 at 4:53am
Hello
    why crystal report asking me every time username password when i load the data from database through vb.net?
Thanks

-------------
a



Replies:
Posted By: hilfy
Date Posted: 02 Dec 2008 at 12:12pm
Are you using a .NET dataset or does your report connect to the database?
 
If you're using a .NET dataset, you need to make sure that you set the datasource of the report to point to the current instance of the dataset prior to setting the reportsource of the viewer.  I don't work in VB.NET, but in C# I usually overload the creator of the viewer form so that the form that generates the data can pass the dataset to the viewer.  I then create the report object, set its dataset, and then set the reportsource of the viewer.  The code looks something like this:

public CrystalDocReportViewer(DataSet ds)
{
  InitializeComponent();
  rpt
= new CrystalDocReport();
  rpt
.SetDataSource(ds);
  viewer
.ReportSource = rpt;
}
 
If you're not using a dataset, but connecting the report to the database, then you have to set the login values when you run the report.  We do it this way:

CrystalDecisions.Shared.ConnectionInfo connectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
connectionInfo.ServerName = qServer;
connectionInfo.UserID = rptUserID;
connectionInfo.Password = rptPassword;
 
// set report connection for main report
Tables tables = crReport.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
  TableLogOnInfo tableLogonInfo = table.LogOnInfo;
  tableLogonInfo.ConnectionInfo = connectionInfo;
  table.ApplyLogOnInfo(tableLogonInfo);
}

// set report connection for any subreports
Sections sections = crReport.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);
      tables = subReportDocument.Database.Tables;
      foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
      {
        TableLogOnInfo tableLogonInfo = table.LogOnInfo;
        tableLogonInfo.ConnectionInfo = connectionInfo;
        table.ApplyLogOnInfo(tableLogonInfo);
      }
    }
  }
}


-Dell



-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics



Print Page | Close Window