Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access session variable in SSRS (SQL Server 2012)?

I want to access the session or viewstate variables in SSRS 2012 reports just like we access in c#.

Session["user"]

I want to access like this in SSRS report.

I want to include the user who is logged in when the report is generated.

Is there any way to achieve this? Can we access it in custom code in SSRS?

like image 868
Mark Avatar asked Nov 02 '22 21:11

Mark


1 Answers

In the code behind, you could copy the desired data at a report parameter.

    // Copy the session username to a report param called "CurrentUser".
    ReportParameter userParam = new ReportParameter("CurrentUser", Session["user"]);

    // add the parameter to the report
    reportViewer.ServerReport.SetParameters(new ReportParameter[] { userParam });

And then add your parameter to the report as you would any other parameter. See example at: http://msdn.microsoft.com/en-us/library/aa337091.aspx

like image 194
Dan Sorensen Avatar answered Nov 15 '22 05:11

Dan Sorensen