Showing posts with label impersonate. Show all posts
Showing posts with label impersonate. Show all posts

Friday, February 24, 2012

How to impersonate user for data on another server?

Hello all,

I have a quick question. The sql reporting server is on server A, and the actual data for the report is on a sql server 2005 called server B. When I am actually developing my report and click preview, everything works perfectly using windows authentication. However, whenever I publish and try to view the report, i get this error:

  • An error has occurred during report processing.
  • Cannot create a connection to data source 'serverB'.
  • Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.How do I change the login for this datasource while still using windows authentication and not mixed mode?

    ThanksGo to the data source properties in the Reporting Services Manager and you can put in a Windows or SQL Server user name and password for the data source.

  • How to impersonate the user and send those credentials?

    I want to create only one user on the domain, and my application should send that user and password to the reportviewer, in that way I wont have to give permissions to every user individually .

    Does anyone have the lines of code to do this?

    Check the WindowsIdentity class (particularly WindowsIdentity.Impersonate): http://msdn2.microsoft.com/en-us/library/system.security.principal.windowsidentity(VS.80).aspx

    -- Robert

    How to impersonate the user and send those credentials?

    I want to create only one user on the domain, and my application should send that user and password to the reportviewer, in that way I wont have to give permissions to every user individually .

    Does anyone have the lines of code to do this?

    Try one of these articles:

    http://www.odetocode.com/Articles/215.aspx

    http://www.odetocode.com/Articles/216.aspx|||Hey I STRUGGLED with this for some time and from grabbing other snippets of code and doing some of my own troubleshooting this is what I came up with and it works for me. Please note that in the second line of code you will need the IMPORTS of YOUR web service. I am using Webhost4life as my provider and this code works for me so I hope it helps someone out there to get started. If anyone has enhancements please let me know.

    Imports Microsoft.VisualBasicImports com.mysite4now.sql332reportingImports Microsoft.Reporting.WebFormsImports System.Security.PrincipalPartialClass reportviewerInherits System.Web.UI.PagePublic Class ReportViewerCredentialsImplements IReportServerCredentialsPrivate _userNameAs String Private _passwordAs String Private _domainAs String Public Sub New(ByVal userNameAs String,ByVal passwordAs String,ByVal domainAs String) _userName = userName _password = password _domain = domainEnd Sub Public ReadOnly Property ImpersonationUser()As System.Security.Principal.WindowsIdentityImplements Microsoft.Reporting.WebForms.IReportServerCredentials.ImpersonationUserGet Return Nothing End Get End Property Public ReadOnly Property NetworkCredentials()As System.Net.ICredentialsImplements Microsoft.Reporting.WebForms.IReportServerCredentials.NetworkCredentialsGet Return New Net.NetworkCredential(_userName, _password, _domain)End Get End Property Public Function GetFormsCredentials(ByRef authCookieAs System.Net.Cookie,ByRef userNameAs String,ByRef passwordAs String,ByRef authorityAs String)As Boolean Implements Microsoft.Reporting.WebForms.IReportServerCredentials.GetFormsCredentials userName = _userName password = _password authority = _domainReturn Nothing End Function End Class Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.LoadIf Not IsPostBackThen Dim rptPathAs String rptPath = Request("Path")Dim rsAs New ReportingService ReportViewer1.ServerReport.ReportServerCredentials =New ReportViewerCredentials("username","password","") ReportViewer1.ServerReport.ReportServerUrl =New Uri("yourservername") ReportViewer1.AsyncRendering =False ReportViewer1.ShowDocumentMapButton =True ReportViewer1.DocumentMapCollapsed =False ReportViewer1.ServerReport.ReportPath = rptPathEnd If End SubEnd Class
    |||

    Hey, can i ask you for this line:
    ReportViewer1.ServerReport.ReportServerCredentials = New ReportViewerCredentials("username", "password", "")

    How you get the the password variable? if it from your database or from active directory?

    Please advice, thank you.

    |||

    you can put it in, web.config or from a database. don't know abt active directory.

    I have worked with this, and we put it in web.config.

    i haven't tried for active directory.

    How to impersonate known user to AS 2000

    I am developing an application in C# 2.0 that will access a AS 2000 cube. I want the application to access the cube with a known account. I do not want to use XMLA.

    My ConnectionString looks like this:

    Data Source=MyServer; Catalog=GL; User ID=ReportUser; Password=mypass

    My code looks like this:

    AdomdConnection Connection = new AdomdConnection(ConnectionString);
    Connection.Open();

    ReportUser is a local account on the server. The cube has a single role where ReportUser is a member.

    When trying to open the connection I get an exception that the connection was actively refused by the server.

    Help?

    Thanks

    Sorry - you can't do that unless you set up http authentication and use basic auth for your virtual directory. (please use https)

    And that takes Enterprise edition in 2000 (but standard in 2005!).