{"id":126,"date":"2008-08-21T15:10:00","date_gmt":"2008-08-21T15:10:00","guid":{"rendered":"\/lisa\/post\/2008\/08\/21\/Walkthrough-Integrated-authentication-and-your-report-procedures.aspx"},"modified":"2008-08-21T15:10:00","modified_gmt":"2008-08-21T15:10:00","slug":"walkthrough-integrated-authentication-and-your-report-procedures","status":"publish","type":"post","link":"https:\/\/spacefold.com\/lisa\/2008\/08\/21\/walkthrough-integrated-authentication-and-your-report-procedures\/","title":{"rendered":"Walkthrough: Integrated authentication and your report procedures"},"content":{"rendered":"<p align=\"left\">\nHi everybody,\n<\/p>\n<p>\nIt&#39;s been more than a month since my last blog-confession.&nbsp; Life is totally getting in the way here, in the form of new job responsibilities and yet-another-move.\n<\/p>\n<p>\nI have promised three&nbsp;nice people&nbsp;in the last 24 hours that I would address their SQL RS questions here as soon as I can. I hope they don&#39;t get annoyed, I&#39;m bumping another question up to the head of the line&#8230; and I really will post more regularly, soon, I promise.&nbsp;\n<\/p>\n<p>\nA co-worker here at <a href=\"http:\/\/ecwise.com\" class=\"ecwLogoRef\"><span class=\"ecwLogoOrange\">EC<\/span><span class=\"ecwLogoGray\">|<\/span><span class=\"ecwLogoBlack\">Wise<\/span><\/a> had a question, and his question pointed out to me something that, while it&nbsp;should be obvious in RS, and while it actually is easy,&nbsp;just&#8230; isn&#39;t&#8230; obvious at all&#8230;\n<\/p>\n<p>\n&#8230; so it&#39;s a&nbsp;good item to highlight here.&nbsp; (With any luck at least one of the three nice people from the past 24 hours&#39; worth of questions will be helped, too!)\n<\/p>\n<p>\nHere&#39;s the scenario:\n<\/p>\n<p>\nYou use integrated authentication in your intranet site, and you create RS reports to analyze the data on that site.&nbsp;\n<\/p>\n<p>\nNormally, your ASP.NET code passes a parameter with the current user identity to&nbsp;your stored procedures, to limit the data displayed to any individual.&nbsp; Your database maintains tables of user privilege and role.&nbsp; <strong>So how do you make sure that the user sees only the correct data in your RS reports?<\/strong>\n<\/p>\n<p>\nThe simple answer is &quot;Same way as you do in your ASP.NET application.&nbsp; You pass a parameter with the user identity, which Reporting Services exposes very nicely for you in the form of the global variable <strong>User!UserID<\/strong>&quot;.\n<\/p>\n<p align=\"center\">\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 440px; height: 322px\" src=\"\/lisa\/wp-non\/migrated\/RSGlobalVars.PNG\" alt=\"Expression dialog shows report-global variable set, including User!UserID\" title=\"Expression dialog shows report-global variable set, including User!UserID\" width=\"440\" height=\"322\" \/>\n<\/p>\n<p align=\"left\">\nI suppose it&#39;s possible that some people don&#39;t even know that the Globals exist at all.&nbsp; Hence the screenshot above.&nbsp;\n<\/p>\n<p align=\"left\">\nBut it&#39;s more <em>likely<\/em> that the not-obvious part is how to supply those globals as arguments to your stored procedure code, just as you would from ASP.NET.&nbsp; Hence the walkthrough below.\n<\/p>\n<p align=\"left\">\nReady?\n<\/p>\n<h4 align=\"left\">1. The sample report setup<\/h4>\n<p align=\"left\">\nMy co-worker&#39;s actual report involves some cascading report parameters, each one of which is fed by a stored procedure.&nbsp; Each stored procedure shows up as a separate dataset for the report, and these datasets supply the picklists for limiting report data.&nbsp;\n<\/p>\n<p align=\"left\">\nWhat he needs to do is pass the user identity to the stored procedure that populates the <em>first<\/em>&nbsp; picklist in the cascade, which in turn will limit the data in all the other picklists.&nbsp;\n<\/p>\n<p align=\"left\">\nThere are many other possible scenarios &#8212; he might need to pass the user id to every stored procedure, to filter each picklist separately.&nbsp; That&#39;s fine, they would all work the same way.\n<\/p>\n<p align=\"left\">\nIn my example, I&#39;ll use a simple report from AdventureWorks data, and I&#39;ll drive the main body of the report by a stored procedure, which gets a list of cities by StateProvinceID.&nbsp; While this procedure happens to use a picklist parameter as well, I&#39;ll actually pass <strong>User!UserID<\/strong> to the main stored procedure, driving the report data.&nbsp; This will make the whole thing easy to see.\n<\/p>\n<p align=\"left\">\nSo let&#39;s consider the &quot;main&quot; stored procedure, shown in the following screenshot:\n<\/p>\n<div style=\"text-align: center\">\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 515px; height: 261px\" src=\"\/lisa\/wp-non\/migrated\/AWGetCitiesSProc.PNG\" alt=\"Stored procedure receives the identity value\" title=\"Stored procedure receives the identity value\" width=\"515\" height=\"261\" \/>\n<\/div>\n<p align=\"left\">\n&nbsp;\n<\/p>\n<p align=\"left\">\n&#8230; yeah, it&#39;s not much to look at.&nbsp;\n<\/p>\n<p align=\"left\">\nThis sproc has one parameter that is tied to a report parameter (StateProvinceID) and the other is tied to our user&#39;s identity, even though the procedure doesn&#39;t do much with the user except send it back for display purposes.\n<\/p>\n<p align=\"left\">\nWe have a second dataset feeding our picklist parameter in this report.&nbsp; We fill this dataset using a simple <strong>SELECT&nbsp;&nbsp;Name, StateProvinceID FROM&nbsp;&nbsp;Person.StateProvince<\/strong>,&nbsp; nothing fancy.\n<\/p>\n<p align=\"left\">\nOK so far?\n<\/p>\n<h5 align=\"left\">Quick review: driving the picklist with a parameter<\/h5>\n<p align=\"left\">\nHere&#39;s our parameter setup; you can see that it has a NULL default value, meaning that the user has to pick a StateProvince (by Name, in this case) to actually run the report.\n<\/p>\n<p align=\"center\">\n<img loading=\"lazy\" decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/StateProvinceIDParam.PNG\" alt=\"StateProvinceID parameter driven by query\" title=\"StateProvinceID parameter driven by query\" width=\"382\" height=\"418\" \/>\n<\/p>\n<h5 align=\"left\">Report layout<\/h5>\n<p align=\"left\">\nOur report layout really has one simple job: demonstrate what the current value of <strong>User!UserID <\/strong>happens to be, and that the value sent to the stored procedure is correct (the same as <strong>User!UserID<\/strong>.\n<\/p>\n<p align=\"center\">\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 484px; height: 140px\" src=\"\/lisa\/wp-non\/migrated\/RSAuthSampleReportLayout.PNG\" alt=\"Sample report layout\" title=\"Sample report layout\" width=\"484\" height=\"140\" \/>\n<\/p>\n<p>\n&#8230; still not very exciting.&nbsp; You can see that, in the header, I show the report-global variable, and in the table, I show the value coming back from the stored procedure.\n<\/p>\n<p>\nWhew. that was a long wind-up.&nbsp; Where&#39;s the beef?\n<\/p>\n<h4>2. The &quot;meat&quot; of the work: passing&nbsp;a report&nbsp;variable to the stored procedure<\/h4>\n<p>\nI&#39;ve set my main data set for the report to use my stored procedure (note Command type):\n<\/p>\n<p align=\"center\">\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 464px; height: 360px\" src=\"\/lisa\/wp-non\/migrated\/AuthDataSet1.PNG\" alt=\"Set up the dataset to read from a stored procedure.\" title=\"Set up the dataset to read from a stored procedure.\" width=\"464\" height=\"360\" \/>\n<\/p>\n<h5>Wait just a gosh-darned moment.&nbsp; <\/h5>\n<p>\nHow did I get to the dialog in the last screen shot?&nbsp; Oh, yes.&nbsp; Another not-obvious thing &#8212; use the ellipsis button on the Report Designer data tab:\n<\/p>\n<p align=\"center\">\n<img loading=\"lazy\" decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/AuthEditDataSet.PNG\" alt=\"\" width=\"555\" height=\"100\" \/>\n<\/p>\n<h5 align=\"left\">Back to&nbsp;configuring the stored procedure&nbsp;<\/h5>\n<p align=\"left\">\nNow go to the Parameters tab in this dialog.&nbsp; See?&nbsp;&nbsp;\n<\/p>\n<p align=\"center\">\n<img loading=\"lazy\" decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/AuthDataSet2.PNG\" alt=\"Bind the parameters\" title=\"Bind the parameters\" width=\"464\" height=\"317\" \/>\n<\/p>\n<p align=\"left\">\nYou can even use intellisense (sort of) to build up an expression.&nbsp;&nbsp;You&#39;ll be using&nbsp;the same dialog as you see in the first screen shot in this post.\n<\/p>\n<h4 align=\"left\">3. The result<\/h4>\n<p align=\"left\">\nThat&#39;s it.&nbsp; Stand back and watch it work&#8230; whether in your IDE for testing or in Report Manager (or otherwise requested from ReportServer)&#8230;\n<\/p>\n<p align=\"center\">\n<img loading=\"lazy\" decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/AuthResult.PNG\" alt=\"Sample report as viewed in Report Manager\" title=\"Sample report as viewed in Report Manager\" width=\"399\" height=\"322\" \/>\n<\/p>\n<p align=\"left\">\nAs they used to say on the cereal commercials, &quot;Stays crunchy, even in millk&quot;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi everybody, It&#39;s been more than a month since my last blog-confession.&nbsp; Life is totally getting in the way here, in the form of new job responsibilities and yet-another-move. I have promised three&nbsp;nice people&nbsp;in the last 24 hours that I would address their SQL RS questions here as soon as I can. I hope they<a class=\"more-link\" href=\"https:\/\/spacefold.com\/lisa\/2008\/08\/21\/walkthrough-integrated-authentication-and-your-report-procedures\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5,6],"tags":[],"class_list":["post-126","post","type-post","status-publish","format-standard","hentry","category-asp-net","category-reporting","category-sql-server"],"_links":{"self":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts\/126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/comments?post=126"}],"version-history":[{"count":0,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts\/126\/revisions"}],"wp:attachment":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/media?parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/categories?post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/tags?post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}