Monday, February 22, 2010

Crystal Report with Asp.NET – Direct method using server credentials

In this we are going to create a database connection using server user name and password. For this do the all the steps as previous post until

Make New Connection to Create a New DB connection,

in there give server name, username and password. If everything is correct you can select the server database in your list.

image  

Then click next and finished the wizard.
So you can view your tables in the Field explorer as previous post . Now you can design your report by drag and dropping fields.

Finally save you report as report1.rpt. 

 

Now not like the previous, we want to give server credentials when we Load the report. Thus following codes you can use to  give credentials in report.aspx

protected void Page_Load(object sender, EventArgs e)
{
ReportDocument CollReport = new ReportDocument();
string reportPath = Server.MapPath("Report1.rpt");
CollReport.Load(reportPath);
CollReport.SetDatabaseLogon("username", "password", "servername", "db");
CrystalReportViewer1.ReportSource = CollReport;
}
Post a Comment