2015-11-24 105 views
1

我正在爲類的項目工作,我們需要生成水晶報告。我正在使用Visual Studio 2013並使用Crystal Reports for SP15進行操作。我創建了一個報告,並在空白的asp.net webform上放置了一個水晶查看器,但是當我運行webform時,它要求輸入數據庫登錄信息。有沒有人遇到過這個問題,或任何人都可以幫助我嗎?謝謝!如何繞過Visual Studio 2013中Crystal Reports的登錄屏幕?

**這裏是我的webfrom頁面代碼:

Imports CrystalDecisions.CrystalReports.Engine 
Imports CrystalDecisions.Shared 
Imports System.Data 
Imports System.Data.SqlClient 

Partial Class Default2 
    Inherits System.Web.UI.Page 

    Dim MyReport As SqlConnection 
    Dim COMMAND As ReportDocument 
    Dim ALMOST As SqlCommand 
    Dim adp As SqlDataAdapter 
    Dim DT As DataSet 

    Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click 

     Dim commandString As String = ConfigurationManager.ConnectionStrings("HouseSwappingConnectionString").ConnectionString 
     Using con As New SqlConnection(commandString) 

      Using cmd As New SqlCommand("Select * from ListTable", con) 
       cmd.CommandType = CommandType.Text 
       Dim da As New SqlDataAdapter(cmd) 
       Dim ds As New DataSet 
       da.Fill(ds) 

       Dim HouseSwap As New ReportDocument 
       HouseSwap.Load(Server.MapPath("CrystalReport.rpt")) 
       HouseSwap.SetDataSource(ds.Tables(0)) 

       CrystalReportViewer1.ReportSource = HouseSwap 
       CrystalReportViewer1.DataBind() 
       CrystalReportViewer1.RefreshReport() 

      End Using 
     End Using 
    End Sub 

回答

0

報表動態設置登錄參數,所以它不會在運行時對登錄參數要求。 首先初始化像

Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo 

現在連接參數定義連接參數coninfo

 ConInfo.ConnectionInfo.ServerName = ServerIP ' change with server name 
     ConInfo.ConnectionInfo.DatabaseName = DBname ' change with database name 
     ConInfo.ConnectionInfo.UserID = "sa" 
     ConInfo.ConnectionInfo.Password = DBPassword ' change with your password 

現在在水晶報表數據源設置登錄信息,因爲這

For intCounter As Integer = 0 To HouseSwap .Database.Tables.Count - 1 
      HouseSwap .Database.Tables(intCounter).ApplyLogOnInfo(ConInfo) 
Next 

組中的所有表這在設置report.hope的數據源之前有幫助。

+0

好的,謝謝。我對ASP.net來說比較新,所以你能解釋一下我到底能找到我的服務器名稱,數據庫名稱和密碼嗎?我可能會對我所輸入的內容感到困惑。 –

+0

查看連接字符串。 –