locked
Getting Windows USERID in SSRS report RRS feed

  • Question

  • Hi,

     

    I'd like to keep track the my reports users. I have stored procedure and I am passing userid to it. It work in development server but in production server it always  gets Production server's generic userid.

    The users connect to reporting server by windows authentication. I use  below code to get the user id and pass to the stored procedure.

     

    DECLARE @userid varchar(8)
    SET              @userid = UPPER ((SELECT     RIGHT(ORIGINAL_LOGIN(), Len(ORIGINAL_LOGIN()) - charindex('\', ORIGINAL_LOGIN()))))

     

    is there way to get windows user id in ssrs report?

     

    Thanks

    Burak


    Monday, August 22, 2011 6:47 PM

Answers

  • Hi,
    The built in fields like User!UserID are available from any formula window - report builder or visual studion.
    i.e. If you would like to pass the user id to your stored procedure, the stored procedure has to have a parameter like userid.
    As soon as you connect the report to your stored procedure the report should have an parameter @userid at the parameter folder. 
    Click the property of the parameter - click default values - specific values - click add button - click the formula button - at the category you will see the built in fields.
    regarding log information:
    open the SQL server management studio - connect to the SSRS database - at the database folder you find the report database - at views you should see the executionlog view,
    This view shows you all executed reports, size, duration, export format, userid ....
    wmel
    • Marked as answer by Burakcan Wednesday, August 24, 2011 4:26 PM
    Tuesday, August 23, 2011 12:35 PM
  • Hi,

    did you check if the parameter got created at you data set too?
    right mouse click data set - data set properties - parameters, there you should have a parameter name=@userid, parameter value=[@userid],
    if not add it.
    you also have to make sure that the parameter name at you stored procedure is the same.
    wmel

    • Proposed as answer by Lola Wang Wednesday, August 24, 2011 4:52 AM
    • Marked as answer by Burakcan Wednesday, August 24, 2011 4:26 PM
    Tuesday, August 23, 2011 7:37 PM

All replies

  • Hi,
    you get the windows user id in SSRS with the build in field - User!UserID
    Do you know that at the SSRS reporting database is a view that returns statistic information about all executed reports, it also shows the user id.
    Please let me know if that was helpful
    wmel
    Monday, August 22, 2011 9:46 PM
  • Hi,

     

    I don't have much experience with SSRS. Can you please explain it more. If you have an example it would be better.

    Thanks

    Burak

    Tuesday, August 23, 2011 11:00 AM
  • Hi,
    The built in fields like User!UserID are available from any formula window - report builder or visual studion.
    i.e. If you would like to pass the user id to your stored procedure, the stored procedure has to have a parameter like userid.
    As soon as you connect the report to your stored procedure the report should have an parameter @userid at the parameter folder. 
    Click the property of the parameter - click default values - specific values - click add button - click the formula button - at the category you will see the built in fields.
    regarding log information:
    open the SQL server management studio - connect to the SSRS database - at the database folder you find the report database - at views you should see the executionlog view,
    This view shows you all executed reports, size, duration, export format, userid ....
    wmel
    • Marked as answer by Burakcan Wednesday, August 24, 2011 4:26 PM
    Tuesday, August 23, 2011 12:35 PM
  • Hi,

    I have created parameter @userid then Click the property of the parameter - click default values - specific values - click add button then i chose built-in field then chose =User!UserID then hit the OK button it shows [&UserID]  as a value then I hit the Ok again. When I try to run it  I got below message :

     

    The value expression for the query parameter '@userid' refers to a non-existing report parameter 'userid'  


    Tuesday, August 23, 2011 5:10 PM
  • Hi,

    did you check if the parameter got created at you data set too?
    right mouse click data set - data set properties - parameters, there you should have a parameter name=@userid, parameter value=[@userid],
    if not add it.
    you also have to make sure that the parameter name at you stored procedure is the same.
    wmel

    • Proposed as answer by Lola Wang Wednesday, August 24, 2011 4:52 AM
    • Marked as answer by Burakcan Wednesday, August 24, 2011 4:26 PM
    Tuesday, August 23, 2011 7:37 PM
  • Hi Wmel,

     

    It works!.

    Thank you very much.


    Burak



    Wednesday, August 24, 2011 1:33 PM
  • Hi Burak,

    Please mark as answer if helpful

    Thank's

    wmel

    • Marked as answer by Burakcan Wednesday, August 24, 2011 4:26 PM
    • Unmarked as answer by Burakcan Wednesday, August 24, 2011 4:26 PM
    Wednesday, August 24, 2011 3:59 PM
  • Hi Wmel,

    Do you know where is built in userID cached?

    Wednesday, February 22, 2012 5:37 AM
  • Hi Wmel,

    Do you know where is built in userID cached?

    It's stored in ReportServer.dbo.Users table (UserName column).

    In the case of Windows Authentication it will be in the form of Domain\LoginID

    Monday, February 2, 2015 5:39 PM