Monday, February 15, 2016

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?



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

No comments:

Post a Comment