Sql Server Report on Asp.net

Hi,

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.
mismail75Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TSmoothCommented:
You will need to setup proper credentials for your asp.net site to access the reporting server. Is the SQL Server reporting server on the same machine as the asp.net 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 asp.net 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
        Get
 
            '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
        Get
 
            '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 = _
                ConfigurationManager.AppSettings("MyReportViewerUser")
 
            If (String.IsNullOrEmpty(userName)) Then
                Throw New Exception("Missing user name from web.config file")
            End If
 
            'Password
            Dim password As String = _
                ConfigurationManager.AppSettings("MyReportViewerPassword")
 
            If (String.IsNullOrEmpty(password)) Then
                Throw New Exception("Missing password from web.config file")
            End If
 
            'Domain
            Dim domain As String = _
                ConfigurationManager.AppSettings("MyReportViewerDomain")
 
            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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.