2017-01-03 96 views
0

我已閱讀所有關於在stackoverflow中相關的問題的答案。爲什麼Crystal報告要求提供數據庫登錄憑據?

但我無法從這些問題獲得幫助。

我的代碼

Imports System.Data.SqlClient 
Imports System.Data 
Imports System.Windows.Forms 
Imports CrystalDecisions.Shared 

Partial Class Reports_LReport 
Inherits System.Web.UI.Page 
Public Report As New CrystalDecisions.CrystalReports.Engine.ReportDocument() 
Public thisConnectionString As String = ConfigurationManager.ConnectionStrings("cnStringMain").ConnectionString 
Dim reportDocument As CrystalDecisions.CrystalReports.Engine.ReportDocument = Nothing 


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) 
    Dim scriptManager__1 As ScriptManager = ScriptManager.GetCurrent(Me) 
    scriptManager__1.RegisterPostBackControl(Me.FactroyAttendance) 

    If Not IsPostBack = True Then 

    Else 
    LoadReport() 
    End If 
    End Sub 


Protected Sub cmdShow_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdShow.Click 
    LoadReport() 
End Sub 


Private Sub LoadReport() 


    If Me.reportDocument IsNot Nothing Then 
     Me.reportDocument.Close() 
     Me.reportDocument.Dispose() 
    End If 
    Dim SConn As New SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings("cnStringMain").ConnectionString) 
    Dim thisConnection As New SqlConnection(thisConnectionString) 
    Dim mySelectCommand As SqlCommand = New System.Data.SqlClient.SqlCommand("prLeaveStatusReport", thisConnection) 
    mySelectCommand.CommandType = CommandType.StoredProcedure 
    reportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument() 
    Dim reportPath As String = Server.MapPath("~/Reports/JoyLeaveReport.rpt") 
    reportDocument.Load(reportPath) 
    Dim connInfo As New CrystalDecisions.Shared.ConnectionInfo() 
    connInfo.ServerName = SConn.DataSource 
    connInfo.DatabaseName = SConn.InitialCatalog 
    connInfo.UserID = SConn.UserID 
    connInfo.Password = SConn.Password 
    Dim tableLogOnInfo As New CrystalDecisions.Shared.TableLogOnInfo() 
    tableLogOnInfo.ConnectionInfo = connInfo 
    For Each table As CrystalDecisions.CrystalReports.Engine.Table In reportDocument.Database.Tables 
     table.ApplyLogOnInfo(tableLogOnInfo) 
     table.LogOnInfo.ConnectionInfo.ServerName = connInfo.ServerName 
     table.LogOnInfo.ConnectionInfo.DatabaseName = connInfo.DatabaseName 
     table.LogOnInfo.ConnectionInfo.UserID = connInfo.UserID 
     table.LogOnInfo.ConnectionInfo.Password = connInfo.Password 
     table.Location = "dbo." + table.Location 
    Next 


    If String.IsNullOrEmpty(txtFrom.Text) Then 
     reportDocument.SetParameterValue("@dateFrom", "") 
    Else 
     reportDocument.SetParameterValue("@dateFrom", Convert.ToDateTime(txtFrom.Text).ToString("yyyy-MM-dd HH:mm:ss")) 

    End If 

    If String.IsNullOrEmpty(txtEmployeeID.Text) Then 
     reportDocument.SetParameterValue("@empId", "") 
    Else 
     reportDocument.SetParameterValue("@empId", txtEmployeeID.Text) 
    End If 


    If String.IsNullOrEmpty(txtTo.Text) Then 
     reportDocument.SetParameterValue("@dateTo", "") 
    Else 
     reportDocument.SetParameterValue("@dateTo", Convert.ToDateTime(txtTo.Text).ToString("yyyy-MM-dd HH:mm:ss")) 

    End If 

     FactroyAttendance.ReportSource = reportDocument 
     FactroyAttendance.DataBind() 
     FactroyAttendance.ReportSource = reportDocument 
     FactroyAttendance.DataBind() 



End Sub 

Protected Sub Page_Unload(ByVal sender As Object, ByVal e As EventArgs) 
    If Me.reportDocument IsNot Nothing Then 
     Me.reportDocument.Close() 
     Me.reportDocument.Dispose() 
    End If 
End Sub 
End Class 

我有一個從那裏我有三個字段1.沒有fromdate 2. TODATE 3.僱員

我報告工作正常,但是當我去出口用pdf或Word報告它向我詢問參數和數據庫登錄的價值。

圖像1

enter image description here

圖像2 enter image description here

圖像3 enter image description here

所以,我從SI解釋儘可能多的。 我怎麼解決它? 並提前致謝。

+0

[如何停止水晶報表查看器在打開子報表時要求登錄憑據](http://stackoverflow.com/questions/21709438/how-to-stop-crystal-report-viewer-from-asking- login-credentials-when-opening-sub) –

+0

torha matha sala,dekhos na upore ami likhsi je ai問題相關的問題,但我沒有得到任何幫助。 –

回答

1

我看到你把登錄信息正確,所以問題可能是你不緩存你的crystalreport對象。

您需要緩存對象並將其重新綁定到網頁的Page_Init Web方法中。當你在報告中有多個頁面時,以及在我想出口時,這是必要的。

更詳細的信息在這個文檔:http://help.sap.com/businessobject/product_guides/sapCRVS2010/en/crnet13_sp14_dg_en.pdf

頁56(節1.3.3.4),例如。

+0

我沒有得到幫助。我應該再次創建報告嗎? –

+1

您需要緩存您的crystalreport對象,然後在頁面中的init中檢索它並執行 'FactroyAttendance.ReportSource = reportDocument; FactroyAttendance.DataBind();' – Furtiro

+0

解決了:只是添加一個方法。這裏FactoryAttendance是crystalViewer。 [Protected Sub .FactroyAttendance_Load(ByVal sender As Object,ByVal e As EventArgs)Handles FactroyAttendance.Load LoadReport() End Sub] –