Sandy
Sandy

Reputation: 19

How to use crystal report viewer in c# .net

I developed an simple application which asks for data from the user and created a Crystal Report layout using the data set I bound as datasource to the Crystal Report. After running an application it is asking for logon details if I used Crystal Report viewer in my web form. How to resolve it?

Upvotes: 0

Views: 1170

Answers (1)

Furtiro
Furtiro

Reputation: 449

I had same problem, so i checked out the sap CR documentation and found this function :

private void setDatabaseLogon(ReportDocument rd, String databaseName, String  userName, String password)
{

 ConnectionInfo connectionInfo = new ConnectionInfo();

 connectionInfo.DatabaseName = databaseName;
 connectionInfo.UserID = userName;
 connectionInfo.Password = password;

 Tables tables = rd.Database.Tables;

     foreach (Table table in tables)
     {
       TableLogOnInfo newLogonInfo = table.LogOnInfo;
       newLogonInfo.ConnectionInfo = connectionInfo;
       table.ApplyLogOnInfo(newLogonInfo);
     }
}

(here is the C# version but you can found the VB.NET version in the link at the end of my answer)

You'll need to add your database login informations and call this function before rendering your report. So before CrystalReportViewer.DataBind();

References : 1.4.4.1.3

Upvotes: 1

Related Questions