17
Here I’ll talk about how to integrate your asp.net application with Reporting Service through ReportViewer web control which provides rich functionality to deliver Reporting Service Report through asp.net applications. In real life applications; Analysis Service and Reporting Service on server machine, Web Server another server machine and clients usually on another domain access the website to do something. Let’s take a look on this diagram to visualize what happened in intra applications which one of its functionality shows reports this reports actually based on OLAP Data (SSAS used here) Here we build OLAP Cube as Report data source. So, let’s begin to build our report based on Cube which built from AdventureWorksDW 1- Open Microsoft SQL Server Business Intelligence Studio (BIDS) 2005\2008 2- Select Business Intelligence Projects from Project types then create Analysis Services project, with name “AdventureWorksInternetSaleCube”

ramymahrous.files.wordpress.com€¦  · Web view2- Select Business Intelligence Projects from Project types then create Analysis Services project, ... Use mainly to view data without

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ramymahrous.files.wordpress.com€¦  · Web view2- Select Business Intelligence Projects from Project types then create Analysis Services project, ... Use mainly to view data without

Here I’ll talk about how to integrate your asp.net application with Reporting Service through ReportViewer web control which provides rich functionality to deliver Reporting Service Report through asp.net applications.

In real life applications; Analysis Service and Reporting Service on server machine, Web Server another server machine and clients usually on another domain access the website to do something.

Let’s take a look on this diagram to visualize what happened in intra applications which one of its functionality shows reports this reports actually based on OLAP Data (SSAS used here)

Here we build OLAP Cube as Report data source.

So, let’s begin to build our report based on Cube which built from AdventureWorksDW

1- Open Microsoft SQL Server Business Intelligence Studio (BIDS) 2005\20082- Select Business Intelligence Projects from Project types then create Analysis Services project, with name “AdventureWorksInternetSaleCube”

Page 2: ramymahrous.files.wordpress.com€¦  · Web view2- Select Business Intelligence Projects from Project types then create Analysis Services project, ... Use mainly to view data without

Creating Analysis Services Project

3- Press OK 

4- Right click on Data Sources -> New Data Source-> Next; to add connection to AdventureWorksDW. Then from Data Source Wizard press on New which gets Connection Manager dialog to setup your connection to AdventureWorksDW

Page 3: ramymahrous.files.wordpress.com€¦  · Web view2- Select Business Intelligence Projects from Project types then create Analysis Services project, ... Use mainly to view data without

   a. Provider: set the default in our case we need to connect to SQL Server instance   b. Server name: The name of the server which has AdventureWordDW in our guide I’m using mine “RamyMahrous-Lap”  c. Log on to the server: You can use Windows\SQL Authentication in our guide I’m using the default setting which is Windows Authentication  d. Connect or database: Select or enter database name: “AdventureWorksDW”  e. Press on Test Connection to validate it. It must say: Test connection succeeded.  f.  Press OK

Page 4: ramymahrous.files.wordpress.com€¦  · Web view2- Select Business Intelligence Projects from Project types then create Analysis Services project, ... Use mainly to view data without

  g. You’ll find a new connection has been added to Data connections.  h. Press next  i. You come to Impersonation Information dialog: which is what’s user credential you need to connect by to the Analysis Services (which we will use later to build our Cube on) let’s understand the four choices          i. Use a specific windows user name and password: if Analysis service on another machine i.e not on RamyMahrous-lap in our example I should connect to it using a user has access to its machine. Because Analysis service DOESN’T SUPPORT ELSE WINDOWS AUTHENTICATION.          ii. Use the service account: to use the user credentials which the Analysis service starts with (may be you, may be the administrator)          iii. Use the credentials of the current user: YOU          iv. Inherit: to use the default user. Read more about these options on http://technet.microsoft.com/en-us/library/ms187597.aspx

Page 5: ramymahrous.files.wordpress.com€¦  · Web view2- Select Business Intelligence Projects from Project types then create Analysis Services project, ... Use mainly to view data without

  j. Use the one fits your development environment, for me I’ll use Use the service account  k. Next  l. Set the Data source name to “Adventure Works Data Source”  m. Finish  n. You’ll find Adventure Works Data Source.ds added to Data Sources. Adventure Works Data Source.ds in xml file so you can edit it manually but take care if the file being corrupted it’ll affect all the solution5- Right click on Data Source Views->New Data Source View->Next; to add our relational tables which is Cube data source few things should you know about Data Source View  a. Every Data Source View associated to single connection as every Data Source View gets data from one location, if you have multiple server which holds data you need to do multi Data Source Views  b. Use mainly to view data without being have any permission on the database directly; Microsoft helps to calm DBAs down.6- Use our connection “Adventure Works Data Source”, it’s selected by default; Next; you’ll find all available objects (Tables and Views); include those objects FactInternetSales, DimPromotion, DimProduct; then OK; You’ll find Adventure Works DW.dsv created and a new window opens has your three tables and connected together. You can right click on the table to Explore the data on it.

Page 7: ramymahrous.files.wordpress.com€¦  · Web view2- Select Business Intelligence Projects from Project types then create Analysis Services project, ... Use mainly to view data without

7- Right click on Cubes->New Cube-> Next->Use Existing tables->Next; Data Source View: Adventure Works DW (selected by default); Measure group tables-> “FactInternetSales” or you can press suggest to let it select the measure.8- Next; Next; Select Dimensions->Select all9- Next; Finish.10- Congratulation we’ve built the Cube which be the data source for our report.

I’ve passed on creating Cube elements definitions quickly like what’s Fact, dimension, Measure, KPI, Partitions, etc…. because it needs a lot of posts to talk about each of which in details. But I assume you have enough knowledge about SSAS, SSRS and SQL Server relational database concept.

Conclusion:

We’ve showed building Cube using BIDS to be used later as Report data source

In the previous post we learned how to build simple cube using BIDS, and if you’re follower I’ve forgot something important is deployment the cube on the Analysis Services.1- We just need to add some attributes to the dimensions(DimPromotion, DimProduct) as each of which pure (contains just the key) for some reasons we need to show the user the name of product, or the promotion because it very hard to make human treat with numbers contrary to machines which prefer them. We shall add some attributes to the dimensions to make it meaningful.

Page 8: ramymahrous.files.wordpress.com€¦  · Web view2- Select Business Intelligence Projects from Project types then create Analysis Services project, ... Use mainly to view data without

2- Double click on DimPromotion; the dimension design window opened you find Data Source View, Hierarchies and Attributes; simply drag EnglishPromotionName from the Data Source View table to Attributes.3- Repeat the previous step with the DimProduct to add EnglishProductName

4- Right click on AdventureWorksInternetSalesCube project then deploy (to move your cube to the Analysis Services). If deployment succeeded it shows you message Deployment Completed Successfully

Now it’s the time to build our Report.

1- Right click on the solution, then Add->New Project-> Select Business Intelligence Projects from Project types then create Report Server Project Wizard, with name “InternetSalesReport”2- OK

Page 9: ramymahrous.files.wordpress.com€¦  · Web view2- Select Business Intelligence Projects from Project types then create Analysis Services project, ... Use mainly to view data without

3- Report Wizard dialog open, Next; Select New data Source; Type: Microsoft SQL Server Analysis Services then Edit; Server Name: your server name in my case I’ll type “RamyMahrous-Lap” you will notice that when selecting the Data Source as Microsoft SQL Server Analysis Services there is no any chance to login using Username or password as we illustrated in the previous part Analysis Services permits just Windows Authentication. Select or enter database name: “AdventureWorksInternetSalesCube”; Test Connection and then OK if succeeded.

4- Next; we come to the dialog to build the query; press on the Query Builder to open a Query Designer form to help us building the Report Dataset. We need to show ProductEnglishName, PromotionEnglishName, and FactInternetSaleCount and the parameters are ProductEnglishName, and PromotionEnglishName so we’ll drag the ProductEnglishName, PromotionEnglishName, and FactInternetSaleCount on the space which shows “Drag levels or measures here to add to the query”. And ProductEnglishName, and PromotionEnglishName on dimension area and check parameter checkbox. OK

Page 10: ramymahrous.files.wordpress.com€¦  · Web view2- Select Business Intelligence Projects from Project types then create Analysis Services project, ... Use mainly to view data without

5- Next; select report type as Tabular; next; add available fields to details; next;next; rename it to InternetSaleCount_ByProduct_ByPromotion; finish.6- You can preview it and select some criteria to test the report.7- Right click on InternetSalesReport and Deploy to deploy it on the Reporting Service Server to enable users to access it over http. If you got message The specified TargetServerURL is not valid. Specify a valid URL for a report server in the deployment settings. Right click on InternetSalesReport project then properties set the TargetServerURL to http://localhost/ReportServer or your ReportServer URL, check it from IIS.

Conclusion:We’ve showed building Report using BIDS and deploying it on ReportServer.

In the previous two posts building the Cube and building the Report, we discovered how BIDS helps in developing BI applications in robust, managed and organized way. I believe if you have few BI concepts you can do this walkthrough in 10 minutes.Let’s come to the last layer which I see it’s the presentation layer. One question may come to your mind why I build ASP.NET application over Reporting Service? Why I don’t give the end user Reporting Service Server URL. Because of security? NO. Reporting Service Server can manage different types of security which doesn’t put headache on your development team but what if your end user need UI layer say in Silverlight? How can you embed in the Reporting Service. We have ReportViewer Windows\

Page 11: ramymahrous.files.wordpress.com€¦  · Web view2- Select Business Intelligence Projects from Project types then create Analysis Services project, ... Use mainly to view data without

Web control which provides a very rich of functionality to View Reporting Service (Local and Server) Reports. In our walkthrough we use Server Report.Let’s open our previous solution and add a new ASP.NET web application project: InternetSalesWebsiteDefault.aspx page open in source view, switch to Design view. 

From ToolBox->Reporting-> drag MicrosoftReportView control and drop it on the page drag also a Button then close the ToolBox because it slow down VS IDE. (Thanks to Taha Amin how helped me in this)

Page 12: ramymahrous.files.wordpress.com€¦  · Web view2- Select Business Intelligence Projects from Project types then create Analysis Services project, ... Use mainly to view data without

So from ToolBox drag two CheckBoxList, one for product dimension and one for promotion dimensionFor the first CheckBoxList ProductList we need to load Products dimension data into it. Press on the smart arrow then choose data source; select data source select a new data source a new dialog opens, Choose data source type: Database and give the SqlDataSource ID: ProductsDataSource then OK, a new dialog to choose Data Connection, press on New Connection; Data source press change -> ; Data Provider select .NET framework Data Provider For OLE DB then OK; Add connection dialog opens in OLE DB Provider select Microsoft OLE DB Provider For Analysis Services 9.0; Server or file name enter the Analysis Service Server name in my case here “ramymahrous-lap”; Use Windows NT Integrated Security; Intila Catalog “AdventureWorksInternetSalesCube”; Test Connection if succeeded press OKThen Next, save this connection as “InternetSalesConnectionString”; next; Configure Data Source dialog opens; select Specify a Custom SQL Statement or stored procedure; next; error message appears ignore it and press OK; write this MDX script which get Products dataWITHMEMBER [Measures].[ParameterCaption]AS '[Dim Product].[English Product Name].CURRENTMEMBER.MEMBER_CAPTION'MEMBER [Measures].[ParameterValue]AS '[Dim Product].[English Product Name].CURRENTMEMBER.UNIQUENAME'SELECT {[Measures].[ParameterCaption], [Measures].[ParameterValue]}ON COLUMNS , [Dim Product].[English Product Name].ALLMEMBERSON ROWSFROM [Adventure Works DW]

Page 14: ramymahrous.files.wordpress.com€¦  · Web view2- Select Business Intelligence Projects from Project types then create Analysis Services project, ... Use mainly to view data without

Next; Test Query; if it gets data press finish otherwise tell me what you got.

We return back to “Choose Data Source” dialog; Select a data source: ProductsDataSource; Select a data field to display in the CheckBoxList: [Measures].[ParameterCaption]; Select a data field for the value of the CheckBoxList: [Measures].[ParameterValue]; OKRepeat that with Promotion CheckBoxList but you won’t configure the connection again just select “IntertnetSalesConnectionString” from connections and the MDX script would be like thatWITHMEMBER [Measures].[ParameterCaption]AS '[Dim Promotion].[English Promotion Name].CURRENTMEMBER.MEMBER_CAPTION'MEMBER [Measures].[ParameterValue]AS '[Dim Promotion].[English Promotion Name].CURRENTMEMBER.UNIQUENAME'SELECT {[Measures].[ParameterCaption], [Measures].[ParameterValue]}ON COLUMNS , [Dim Promotion].[English Promotion Name].ALLMEMBERSON ROWSFROM [Adventure Works DW]Double click on the button to enter its click event handler to write some code to call the report and

Page 15: ramymahrous.files.wordpress.com€¦  · Web view2- Select Business Intelligence Projects from Project types then create Analysis Services project, ... Use mainly to view data without

pass the parameters value to it.protected void Button1_Click(object sender, EventArgs e){ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote; //work on report resides in the server not localReportViewer1.ShowParameterPrompts = false; //hide parameters area and we will pass it through our controls

 

 

 

 

ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://ramymahrous-lap/Reportserver_SQLSERVER2008/"); //Report Server URL not Report Server Manager URLReportViewer1.ServerReport.ReportPath = "/InternetSaleCount_ByProduct_ByPromotion";//don't put report extension ".rdl"

//using Reporing Service we know InternetSalesReport needs 2 paramters//DimProductEnglishProductName//DimPromotionEnglishPromotionNameList parametersList =new List();

parametersList.Add(GetParameterValue(PromotionList, "DimPromotionEnglishPromotionName"));//fills DimPromotionEnglishPromotionName with selected values user selectedparametersList.Add(GetParameterValue(ProductsList, "DimProductEnglishProductName"));//fills DimProductEnglishProductName with selected values user selected

ReportViewer1.ServerReport.SetParameters(parametersList); //set report paramters with valuesReportViewer1.ServerReport.Refresh(); //display the report}////// Gets every Report parameters value(s)//////Which contains parameter values ///Parameter Name /// Report ParameterMicrosoft.Reporting.WebForms.ReportParameter GetParameterValue(CheckBoxList checkListBox,string parameterName){List parameterValues = new List();

 

Page 16: ramymahrous.files.wordpress.com€¦  · Web view2- Select Business Intelligence Projects from Project types then create Analysis Services project, ... Use mainly to view data without

 

 

 

 

foreach (ListItem li in checkListBox.Items){if (li.Selected){if (li.Text == "All"){parameterValues.Add(li.Value);break; //no need to go through to know if user selected another value.}elseparameterValues.Add(li.Value);}}return new Microsoft.Reporting.WebForms.ReportParameter(parameterName, parameterValues.ToArray(),true);}Press control + F5, to build and view your web application, it should work like that.

We have done.Some important notice you should be aware of1- I didn’t develop data tier, I just filled the CheckBoxList controls with data directly2- To apply our infrastructure architecture First Part you need to have a user have permission to access Reporting Server Server and modify the above code to add some linesReportViewer1.ServerReport.ReportServerCredentials =new ReportServerCredentials(Username, password, domain);you’ll find ReportServerCredentials class attached in the demo.This class developed by someone I don’t remember who is or the site.3- Please if you’ve any question; comment it or contact me on [email protected]

Page 17: ramymahrous.files.wordpress.com€¦  · Web view2- Select Business Intelligence Projects from Project types then create Analysis Services project, ... Use mainly to view data without