Every time I open my form that has a crystal report it always ask for username and password but i did not even use a username and password in my web application. I use integrated security in my web.config. How can I fix this problem?
This is code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
// FOR CRYSTAL REPORT
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using System.Configuration;
// FOR SQL CONNECTION
using System.Data.Sql;
using System.Data.SqlClient;
using MediCard_Cooperative.App_Data;
namespace MediCard_Cooperative.MediCard_Cooperative.Reports
{
public partial class rptTest : System.Web.UI.Page
{
private SqlConnection connSQL;
protected void Page_Load(object sender, EventArgs e)
{
ReportDocument rptDoc = new ReportDocument();
dsMembers ds = new dsMembers(); // .xsd or dataset filename
DataTable dt = new DataTable();
// Set the name of data table
dt.TableName = "Crystal Report Members";
dt = getAllData(); // calling 'getAllMembers' function
ds.Tables[0].Merge(dt);
// .rpt file path "../Reports/SimpleReports.rpt"
rptDoc.Load(Server.MapPath("../Reports/CrystalReports/ctrSample.rpt"));
//set dataset to the report viewer
rptDoc.SetDataSource(ds);
ctrViewerTest.ReportSource = rptDoc;
}
public DataTable getAllData()
{
try
{
using (connSQL = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["connstring"].ToString()))
{
using (SqlCommand cmd = new SqlCommand("usp_Test", connSQL))
{
cmd.CommandType = CommandType.StoredProcedure;
connSQL.Open();
cmd.ExecuteNonQuery();
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataSet ds = new DataSet();
da.Fill(ds, "dtTest");
return ds.Tables[0];
}
}
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}
You will have to mention the database username and password through the ReportDocument
object.
rptDoc.SetDatabaseLogon(username, password);