Sql Server Report on

Posted on 2008-11-05
Last Modified: 2012-08-13

When I am trying to show Reports on .Aspx page form Virtual Directory it is showing this error "The permissions granted to user 'NT AUTHORITY\NETWORK SERVICE' are insufficient for performing this operation. (rsAccessDenied)" . I have used ReportViewer control and VS 2008,  it is working fine at local host.

Thank you.
Question by:mismail75
    1 Comment
    LVL 16

    Accepted Solution

    You will need to setup proper credentials for your site to access the reporting server. Is the SQL Server reporting server on the same machine as the web server where your page will be hosted? If not, you will need your report viewer control to essentially "log in" to the report server on an account that is granted permission to access reports through SQL Server report server's configuration.

    Here's a sample of how you can specify separate credentials for your reports.

    Add a new class to your and set it up lik the code below. Then in your web.config, you will need to add the following properties to your <appSettings> section, replacing with appropriate values:

    <add key="MyReportViewerUser" value="MyUser"/>
        <add key="MyReportViewerPassword" value="MyUserPassword"/>
        <add key="MyReportViewerDomain" value="MyUserDomain"/>

    Finally, on the page that contains your report viewer control, do the following in something like the load event of the page:
    ReportViewer1.ServerReport.ReportPath = "yourReportPath"
    ReportViewer1.ServerReport.ReportServerUrl = "yourReportServerUrl"
    ReportViewer1.ServerReport.ReportServerCredentials = New MyReportServerCredentials()

    Hopefully this gets you on the right track.

    ' --------------- Class to add to ASP.NET Project
    Imports System.Security.Principal
    Imports Microsoft.Reporting.WebForms
    Imports System.Net
    <Serializable()> _
    Public NotInheritable Class MyReportServerCredentials
        Implements IReportServerCredentials
        Public ReadOnly Property ImpersonationUser() As WindowsIdentity _
                Implements IReportServerCredentials.ImpersonationUser
                'Use the default windows user.  Credentials will be
                'provided by the NetworkCredentials property.
                Return Nothing
            End Get
        End Property
        Public ReadOnly Property NetworkCredentials() As ICredentials _
                Implements IReportServerCredentials.NetworkCredentials
                'Read the user information from the web.config file.  
                'By reading the information on demand instead of storing 
                'it, the credentials will not be stored in session, 
                'reducing the vulnerable surface area to the web.config 
                'file, which can be secured with an ACL.
                'User name
                Dim userName As String = _
                If (String.IsNullOrEmpty(userName)) Then
                    Throw New Exception("Missing user name from web.config file")
                End If
                Dim password As String = _
                If (String.IsNullOrEmpty(password)) Then
                    Throw New Exception("Missing password from web.config file")
                End If
                Dim domain As String = _
                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

    Open in new window


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now