none
ReportViewer的遠端處理問題 RRS feed

  • 問題

  • 各位好:

    在WinForm中使用ReportViewer連結遠端的Report Server的報表,應該要如何設定ReportViewer1.ServerReport.ReportServerCredentials的值,因為在微軟官方文件說明要使用IReportServerCredentials來設定ReportViewer,但是小弟只懂VB,而在微軟官方文件是用C#來做範例,看不懂,想請教各高手應如何用VB設定。

    2007年3月19日 上午 11:22

所有回覆

  • 您好:

    小弟參照說明文件,在WinForm寫了以下程式,但是系統告訴我ReportServerCredentials 是ReadOnly不可以設定,想請問我應該如何設定ReportServerCredentials,以下是程式碼。

    Imports System.Net
    Imports System.Security.Principal
    Imports Microsoft.Reporting.WinForms

    Public Class Form4

        Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote
            ReportViewer1.ServerReport.ReportServerUrl = New Uri("http://db/reportserver")
            ReportViewer1.ServerReport.ReportPath = "/ch04/Report1"

            ReportViewer1.ServerReport.ReportServerCredentials = New MyReportServerCredentials()
            ReportViewer1.Dock = DockStyle.Fill
            ReportViewer1.RefreshReport()

        End Sub


    End Class

    <Serializable()> _
    Public NotInheritable Class MyReportServerCredentials
        Implements IReportServerCredentials

        Public ReadOnly Property ImpersonationUser() As WindowsIdentity _
                Implements IReportServerCredentials.ImpersonationUser
            Get

                 Return Nothing

            End Get
        End Property

        Public ReadOnly Property NetworkCredentials() As ICredentials _
                Implements IReportServerCredentials.NetworkCredentials
            Get

                'User name
                Dim userName As String = "abc"

                If (String.IsNullOrEmpty(userName)) Then
                    Throw New Exception("Missing user name from web.config file")
                End If

                'Password
                Dim password As String = "1234"

                If (String.IsNullOrEmpty(password)) Then
                    Throw New Exception("Missing password from web.config file")
                End If

                'Domain
                Dim domain As String = "http://db/ReportServer"

                If (String.IsNullOrEmpty(domain)) Then
                    Throw New Exception("Missing domain from web.config file")
                End If

                Return New NetworkCredential(userName, password, domain)

            End Get
        End Property

        Public Function GetFormsCredentials(ByRef authCookie As Cookie, _
                                            ByRef userName As String, _
                                            ByRef password As String, _
                                            ByRef authority As String) _
                                            As Boolean _
                Implements IReportServerCredentials.GetFormsCredentials

            authCookie = Nothing
            userName = Nothing
            password = Nothing
            authority = Nothing

            'Not using form credentials
            Return False

        End Function

    End Class

    2007年3月23日 上午 08:40
  • HI,

    您這樣試試看:

    reportViewer1.ServerReport.ReportServerCredentials.SetFormsCredentials(null, "userName", "password", "domainName");

    tihs

    2007年3月24日 上午 12:34
  • 2007年3月24日 上午 12:40