2012-12-05 96 views
1

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

这是代码:

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

你需要通过代码通过服务器证书。 – sajanyamaha

+0

我该怎么补充? – anonymizer

+0

看到我的回答下面 – sajanyamaha

回答

0

它是无法找到的数据集或用于设计报告中的数据集是通过数据集不同,水晶报表假设您需要登录

。既然你没有将参数传递给你的sp,我认为直接让crystal报表管理它会更好。较少的代码来维护。

+0

你可以给我的代码做到这一点? – anonymizer

+0

在您的代码中使用您创建的数据集(用于设计报告的数据集)。 – Juvil

1

您将不得不通过ReportDocument对象提及数据库用户名和密码。

rptDoc.SetDatabaseLogon(username, password); 
+0

但我没有用户名和密码。我甚至没有在整个项目中使用 – anonymizer

+0

@anonymizer:如果您使用SQL身份验证连接到数据库,那么您必须拥有用户名和密码。检查应用程序配置文件中的“connstring”值。否则,如果您使用Windows身份验证连接到数据库,那么您可以尝试sajanyamaha的答案。 – Sandeep

1

你需要通过代码通过服务器证书

rptDoc.SetDatabaseLogon(yourDatabaseServerUsername, yourDatabaseServerPassword); 

rptDoc.SetDatabaseLogon("sa", "123"); 
+0

它没有工作:( – anonymizer

+0

试试这个链接http://stackoverflow.com/questions/11473407/crystal-reports-why-is-it-asking-for-database-login-even-after-i-provided-the -d – sajanyamaha

+0

我认为代码没有使用数据集 – anonymizer

1

打开在C#或VB Crystal报表无论你是使用 然后 转到 场浏览器 并右键点击数据库字段 像 enter image description here

,然后选择设置数据源位置...

一个新的窗口将打开...... 展开的属性。

enter image description here

然后找到集成安全 它将被默认为false将其更改为True

enter image description here