2
votes

so i have a .rpt file and want to display the crystal report in a web form.

i dragged the report viewer onto my web form and set its CrystalReportSource at design time.

when i brows to the page it asks me to enter a sql password and has the SQL server name and user already filled in.

how can i set the DB connection in the code behind and have the page display the report without prompting for a SQL password?

should i just generate a dataset and databind the crystal report viewer to the rpt file and to my data set?

1
that's what I usually do. Create a connection, get the data, bind to the report, show it.Greg Bogumil

1 Answers

2
votes
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;


public partial class crystal_report : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    private void Page_Init(object sender, EventArgs e)
    {
        ConfigureCrystalReports();
    }

    private void ConfigureCrystalReports()
    {

        ConnectionInfo connectionInfo = new ConnectionInfo();
        connectionInfo.DatabaseName = "PMIS";
        connectionInfo.UserID = "PMIS_User";
        connectionInfo.Password = "Welcome1";
        SetDBLogonForReport(connectionInfo);


    }


    private void SetDBLogonForReport(ConnectionInfo connectionInfo) {
        TableLogOnInfos tableLogOnInfos = CrystalReportViewer1.LogOnInfo;

        foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
        {
            tableLogOnInfo.ConnectionInfo = connectionInfo;
        }


    }

}