每次我打开带有水晶报表的表单时,它总是要求输入用户名和密码,但是我什至没有在Web应用程序中使用用户名和密码。我在web.config中使用集成安全性。我该如何解决这个问题?

这是代码:

            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);
                        }
                    }
                }
            }

最佳答案

您必须通过ReportDocument对象提及数据库的用户名和密码。

rptDoc.SetDatabaseLogon(username, password);

关于c# - Crystal 报表询问用户名和密码,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13718270/

10-09 04:24