Tuesday, February 21, 2012

ReportViewer, VS2005 and SSRS 2005

I have developed a web app that uses forms authentication. I wrote it in asp.net 2.0. My server is running windows 2003 server standard and IIS. I have also installed on the same machine SQL Server 2005 with Reporting Services.

From my webapplication, I have a button that the user can click and then I have the Report Viewer control generate a report. However, I do not know how to pass the proper credentials to the report server. I would like to pass one username and password that has permissions to run that report. My code is follows:

Private Sub saveRptAs(ByVal s_rptType As String)
Dim warnings As Microsoft.Reporting.WebForms.Warning()
Dim streamids As String()
Dim mimeType As String
Dim encoding As String
Dim extension As String

ReportViewer1.ServerReport.ReportServerUrl = New Uri("http://myserver/reportserver")
ReportViewer1.ServerReport.ReportPath = "/reports/Individual Report"


Dim test As New NetworkCredential("localuser", "password", "domain")

ReportViewer1.ServerReport.ReportServerCredentials = test

Dim rprameter As ReportParameter = New ReportParameter("user_no", Profile.DTGVariables.SelectedYMNo)
Me.ReportViewer1.ServerReport.SetParameters(New ReportParameter() {rprameter})

Dim bytes As Byte() = ReportViewer1.ServerReport.Render(s_rptType, Nothing, mimeType, encoding, extension, streamids, warnings)
Response.Buffer = True
Response.Clear()
Response.ContentType = mimeType
Response.AddHeader("content-disposition", "attachment; filename=sample." + extension)
Response.BinaryWrite(bytes)
Response.Flush()
Response.End()
End Sub

When I click on the button I get the following message:

Unable to cast object of type 'System.Net.NetworkCredential' to type 'Microsoft.Reporting.WebForms.IReportServerCredentials'.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.InvalidCastException: Unable to cast object of type 'System.Net.NetworkCredential' to type 'Microsoft.Reporting.WebForms.IReportServerCredentials'.

Can someone help me with the credentials issue? Do I need to change Reporting Services to use Forms Authentication?

Your help and insight is greatly appreciated.

Thanks

Nate Dogg

put your credentials in web.config, that's how i worked around it

<identityimpersonate="true"userName="Domain\user"password="password"/>

|||try this - works for me
... ServerReport report = ReportViewer1.ServerReport; report.ReportServerCredentials = new MyReportServerCredentials(); ... class MyReportServerCredentials : IReportServerCredentials{ public MyReportServerCredentials() { } public System.Security.Principal.WindowsIdentity ImpersonationUser { get { return null; // Use default identity. } } public System.Net.ICredentials NetworkCredentials { get { return new System.Net.NetworkCredential("user", "pass", "domain"); } } public bool GetFormsCredentials(out System.Net.Cookie authCookie, out string user, out string password, out string authority) { authCookie = null; user = password = authority = null; return false; // Not use forms credentials to authenticate. } }
|||

Hey guys this is killing me also. I am using webhosting4life.com as my hosting company and have reporting services. I am trying the same thing the original poster is doing and getting the same error message. When I try the impersonate user I get the following error message. All I truly want is for the report viewer to pull open the report and display to the end user...but I need to pass my user name and password over....PLEASE HELP!! I have read several books and none of them touch on this.

Configuration Error

Description:An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message:Could not create Windows user token from the credentials specified in the config file. Error from the operating system 'Unspecified error
'

|||

It appears the error is in the web.config. Implementing theIReportServerCredentials as shown in the previous article works and is a good solution to only having the SRS work under that user context.

No comments:

Post a Comment