none
winforms implementing IReportServerCredentials - Error: Property 'ReportServerCredentials' is 'ReadOnly' RRS feed

  • Question

  •  Hi,

        I got an error in my win form when I tried to load my reports thru reportserver: below of my code in my frmreportviewer when it loads up it throw an exception that "Property 'ReportServerCredentials' is 'ReadOnly'"

    Public Class frmReportViewer

    Private Sub frmReportViewer_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(_ReportServerURL)
        ReportViewer1.ServerReport.ReportPath =
    "/HRIS_EmployeeInformation/EmployeeList"
        ReportViewer1.ServerReport.ReportServerCredentials() = New ReportServerCredentials("administrator", "admin", "WORKGROUP")
        Me.ReportViewer1.RefreshReport()
    End Sub

    End Class

    This is the class for IReportServerCredentials:

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

    Public Class ReportServerCredentials
        
    Implements IReportServerCredentials

    Private _userName As String
    Private _password As String
    Private _domain As String

    Public Sub New(ByVal userName As String, ByVal password As String, ByVal domain As String)
        _userName = userName
        _password = password
        _domain = domain
    End Sub

    Public Function GetFormsCredentials(ByRef authCookie As System.Net.Cookie, ByRef userName As String, ByRef password As String, ByRef authority As String) As Boolean Implements Microsoft.Reporting.WinForms.IReportServerCredentials.GetFormsCredentials
        authCookie =
    Nothing
        userName = password = authority = Nothing
        Return False
    End Function

     Public ReadOnly Property ImpersonationUser() As System.Security.Principal.WindowsIdentity Implements Microsoft.Reporting.WinForms.IReportServerCredentials.ImpersonationUser

    Get
        
    Return Nothing
    End Get 

    End Property

    Public ReadOnly Property NetworkCredentials() As System.Net.ICredentials Implements Microsoft.Reporting.WinForms.IReportServerCredentials.NetworkCredentials

    Get
        
    Return New NetworkCredential(_userName, _password, _domain)
    End Get 

    End Property

    End Class

        any one pls help. thank you.

    best regards,
     


    Jeff®
    Tuesday, August 19, 2008 9:58 AM

Answers

  • Unlike the webforms version of the ReportViewer control which requires you to provide an implementation of the IReportServerCredentials interface, the winforms version of the report viewer implements ReportServerCredentials directly.  In your case, you can just assign your NetworkCredential object to ReportViewer.ServerReport.ReportServerCredentials.NetworkCredentials.
    • Marked as answer by jeffrey_q Wednesday, November 25, 2009 11:38 AM
    Wednesday, August 20, 2008 8:49 PM
    Moderator

All replies

  • Unlike the webforms version of the ReportViewer control which requires you to provide an implementation of the IReportServerCredentials interface, the winforms version of the report viewer implements ReportServerCredentials directly.  In your case, you can just assign your NetworkCredential object to ReportViewer.ServerReport.ReportServerCredentials.NetworkCredentials.
    • Marked as answer by jeffrey_q Wednesday, November 25, 2009 11:38 AM
    Wednesday, August 20, 2008 8:49 PM
    Moderator
  • Thanks Brian

    That took some digging to find out.  Like Brian said ..Winforms behaves differently to Webforms. You cannot assign custom credentials to ReportViewer1.ServerReport.ReportServerCredentials if you use winforms... (is read only...I know weird)....need to assign a network credential object to reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials.

    Thus to save yourselves...here is some code ..

              {

               reportViewer1.ProcessingMode = ProcessingMode.Remote;

                NetworkCredential myCred = new NetworkCredential("MyUserID", "MyPassword", "Domain");
                reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = myCred;

                reportViewer1.ServerReport.ReportServerUrl = new Uri("http://xx.xxx.xxx.xx/ReportServer/");
                reportViewer1.ServerReport.ReportPath = "/MY_REPORT_DIR/MyReport";
                reportViewer1.RefreshReport();
     

              }

    Thursday, February 16, 2012 3:12 PM