2012-12-05 101 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