Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 50 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
50
Dung lượng
1,65 MB
Nội dung
ptg 181 Types of Data Sources Report-Specific Data Sources The report-specific data source should be used only when the data needed to process a report should be restricted to that report. If multiple reports need to access the same data source with the same credentials, you should use a shared data source. This is because maintaining lots of embedded data sources can be cumbersome. After the report has been published to the Report Server, the embedded data source has to be maintained as part of that report. You can use the Report Manager web interface to change the reference from an embedded to a shared data source. Shared Data Sources A shared data source exists on the Report Server as a separate entity. Report developers can define a shared data source in Visual Studio, but it does not overwrite an existing data source by default in the same manner that it overwrites reports. To override a shared data source, you have to set OverwriteDataSources project property to True (see Figure 11.1). 11 A shared data source is useful when . Many reports use data from the same location with the same credentials. . An administrator needs to have an easy way to change the location of a data source for several reports. This is the case, for example, when moving reports from develop- ment to production. Data Source Expressions An expression can be used to define the connection at runtime. A classic case is the differ- ence between an active online transaction processing (OLTP) database and historical data or a data warehouse. Many companies store historical data that is more than six months FIGURE 11.1 OverwriteDataSources project property. From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 182 old in a data warehouse. You would have to determine an appropriate connection from some report-level parameter. Like all expressions, a data source expression would have to be written in Visual Basic.NET and preceded by an equals (=) sign. To define data source expressions, consider the following guidelines: . Do not use a shared data source. You cannot use a data source expression in a shared data source. You must define a report-specific data source for the report instead. . Design the reports using a static connection string. . Do not include credentials in the connection string. When possible, Windows authen- tication is the best way to handle credentials. You can also hard code the credentials through the Data Source Properties dialog box (as discussed later in this chapter). . Use a report parameter to specify the values to be passed to the expression. The para- meter can pull from a list of valid values from a query using a separate data source. Later in this chapter, you will see how to set up parameter dependencies that enable you to do this. . Make sure all the data sources implement the same schema. . Before publishing the report, replace the static connection string with an expression. The following is an example of an expression-based data source for SQL Server: =”Data Source=” &Parameters!DBServer.Value & “;Initial Catalog=NorthWind The preceding example assumes that there is a parameter called DBServer . Data Source Credentials You have several options to supply credentials for a data source (see Figure 11.2): . Windows authentication (integrated security). It is the easiest to use, and the creden- tials are handled separately from the data sources. Using this option, you are also leveraging time-tested Windows security. Because each Windows user has individual credentials, you can assign security restrictions down to a level of an individual user. You can also leverage Windows security groups to handle several users as a group with the same level of permissions. For example, you can set permissions in such a way that an employee’s personal information is available only to the HR group and the employee herself. . Hard-code the credentials. In this case, you just enter login credentials. Report Designer stores encrypted credentials separately from the data source, locally and in the file ProjectName.rptproj.user and then in the Reporting Services database, also in the encrypted form. . Prompt a user for login credentials. CHAPTER 11 Accessing Data From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 183 FIGURE 11.2 Shared Data Source Properties dialog box, Credentials tab. Connection Strings 11 . Use the No Credentials option. This is used for data sources that do not require credentials. . Hard-code credentials in the connection string (not recommended). This approach is not recommended because of the security implications associated with this method. Because the credentials are not encrypted, this approach can easily lead to unautho- rized information access. Connection Strings Connection strings vary widely by the type of processing extensions used in the data set. For example, if you use the OLE DB or ODBC process, you must specify the driver. For SQL Server, you should specify a database name, whereas for Oracle the database name is not required. For XML, just point it to the source by entering a URL in the connection string. In all cases, you should not specify the credentials used in accessing the data source inside the connection string. SSRS stores data source credentials separately. The following are some common connection strings: NOTE We use ***Server to denote a name or an IP address of a server that hosts a data source. For example, SQLServer is the name of a server that hosts a SQLServer data- base. In addition to specifying a name or an IP address, you can use the following to point to a local server: localhost , (local) , and . (dot). All of those work for the .NET Framework data provider, but only (local) works for the SQL OLE DB provider. From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 184 . SQLServer RDBMS. You can connect the .NET Framework data provider, OLE DB data provider for SQL Server, and ODBC. In general, we do not recommend using ODBC because in many cases ODBC providers are several times slower than .NET or OLE DB providers. . SQLServer 2000 and later, where 1433 is a port number. The SQLServer admin- istrator sets a port for an instance of SQLServer during configuration process: Data source=SQLServer\InstanceName,1433;Initial Catalog=DatabaseName . Microsoft OLE DB provider for SQL Server: Provider=SQLOLEDB.1;Data Source=(local);Integrated Security=SSPI;Initial Catalog=AdventureWorks . Analysis Services. Much like with the SQL server, you can connect using several different providers: . The .NET Framework data provider for Analysis Services: data source= OLAPServer;initial catalog=AdventureWorksDW . The Microsoft OLE DB provider for OLAP 8.0. You can use it to connect to SQLServer 2000 and later: provider=MSOLAP.2;data source=OLAPServer;initial catalog=AdventureWorksDW . The Microsoft OLE DB provider for Analysis Services 10.0. You can use it to connect to SQLServer 2008: provider=MSOLAP.4;data source= OLAPServer;initial catalog=AdventureWorksDW . Oracle. We recommend Oracle using network configuration tools and that you set an alias for an Oracle server. For example, where the actual server is at OracleServerAddress:Port/Instance , you can set an alias as OracleServer . . The .NET Framework data provider for Oracle. Oracle is running on Windows, and Windows authentication is set up: Data Source=OracleServer; Integrated Security=Yes; CHAPTER 11 Accessing Data From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 185 Connection Strings 11 . The OLE DB provider for Oracle: Data Source=OracleServer;User ID=userId; Password=userPassword;Provider=OraOLEDB.Oracle.1;Persist Security Info=True; . XML via URL: URL=”http://MyWebServer.com/Queryresults.aspx” . XML via web service: URL=<url>;SOAPAction=<method-uri>[#|/]<method-name> URL=http://ReportServer/reportserver/reportservice.asmx;SOAPAction=”http://sche mas.microsoft.com/sqlserver/2004/05/reporting/reportservices/ListChildren” NOTE When specifying XML as a data source, the credentials should be set to Windows authentication or to No Credentials for anonymous access. Anything else generates an error during runtime. . Report model data source for native mode SSRS: Server=http://ReportServer/reportserver; datasource=/models/AdventureWorks.smdl . Report model data source for SSRS in SharePoint integrated mode: Server=http://ReportServer; datasource=http://ReportServer/SharePointSite/documents /models/AdventureWorks.smdl . SSIS package: -f c:\packagename.dtsx . SAP NetWeaver BI data source: DataSource=http://SAPServer:8000/sap/bw/xml/soap/xmla From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 186 TABLE 11.1 Panes of Graphical Query Designer Pane Function Diagram Displays graphic representations of the tables in the query. Use this pane to select fields and define relationships between tables. Grid Displays a list of fields returned by the query. Use this pane to define aliases, sorting, filtering, grouping, and parameters. . Hyperion Essbase: Data Source=http://HyperionServer:13080/aps/XMLA;Initial Catalog=SalesDB . Teradata: Data Source=TeradataServer;User ID=myUsername;Password=myPassword; Microsoft supplies additional drivers that are not installed by default with SSRS. For example, the Microsoft SQLServer 2008 feature pack (www.microsoft.com/downloads/ details.aspx?FamilyId=C6C3E9EF-BA29-4A43-8D69-A2BED18FE73C&displaylang=en) comes with an IBM DB2 OLE DB driver install. Once you install it, the report driver shows Microsoft OLE DB Provider for DB2 in the OLE DB provider list. Practically all the DBMS vendors supply .NET, OLE DB, or ODBC providers for their data- bases and supply setup and connection string information. In addition, Connectionstrings.com provides connection information for a variety of data sources. Querying Data After a connection is established, your next step is to query the data source. For most rela- tional databases, this involves executing some type of SQL query against the catalog. In the case of Analysis Services, you use Multidimensional Expressions (MDX) queries, and for data mining, you use Data Mining Extensions (DMX) queries. The Graphical Query Designer that comes with Report Designer aids developers in devel- oping queries in any of the preceding languages. For more advanced queries or in cases when the data source is not relational database management system (RDBMS), you can use the Generic Query Designer. Graphical Query Designer The Graphical Query Designer is a tool to aid in the development of the query. Behind the scenes, it connects to the data store to pull tables and views. All you have to do is right- click the top pane to add the table you want and select the columns. If the database has referential integrity, the Graphical Query Designer picks that up, too, and makes the necessary joins automatically. You can also join database tables by dragging columns from one table to the other. Table 11.1 outlines the four panes in the Graphical Query Designer. CHAPTER 11 Accessing Data From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 187 Querying Data 11 Changing the diagram or grid affects the SQL and Result panes. For example, when you add a table to the diagram, it actually adds a database table to the SQL query as it is being generated. This is a good way for users to actually learn SQL. Figure 11.3 shows the Graphical Query Designer. Generic Query Designer The Generic Query Designer is open ended. It is for times when you need more flexibility than the Graphical Query Designer allows. This flexibility is especially helpful for running multiple SQL statements to perform some preprocessing, or for writing dynamic statements based on parameters or custom code. Figure 11.4 shows the Generic Query Designer. Toolbar Result pane SQL pane Grid pane Diagram pane Add table Sort by selected column: ascending/descending Show/hide panes Verify SQL Run query Toggle between graphical and generic query designers Generate GROUP BY Remove filter/selected column from a WHERE clause FIGURE 11.3 Graphical Query Designer. TABLE 11.1 Continued Pane Function Query Displays the Transact-SQL query represented by the Diagram and Grid panes. Use this pane to write or update a query using T-SQL query language. Result Displays the results of the query. To run the query, right-click in any pane, and then click Run. From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 188 CHAPTER 11 Accessing Data FIGURE 11.4 Generic Query Designer. NOTE For both Graphical and Generic Query Designers, make sure to click the OK button after you have completed query modifications. Just closing the Designer window will cancel changes, and you might lose a valuable work. Data Set Properties The data set contains a couple of properties of which developers should be mindful. Those properties are accessible through the Dataset Properties dialog box. To bring up the Dataset Properties dialog box (see Figure 11.5), open the Report Data dockable window (from the main BIDS screen, choose View, Report Data), right-click a data set, and select Dataset Properties from the drop-down menu. The properties are as follows: . The Name of the data set . The Data source or a pointer to a shared data source . The Query type or a type of query for a data set: Text , Table , or Stored Procedure . The Query , which represents a query that retrieves data from the data source From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 189 Querying Data 11 FIGURE 11.5 Dataset Properties dialog box. . The Fields collections, which includes fields retrieved by the query and calculated fields . The Parameters (a parameter in a query string, such as SELECT * FROM Person.Address WHERE City = @City ) and Dataset / Parameters , which are used to limit selected data and must have matching parameters in each for proper report processing . The Filters collection, which further filters result of the query inside of a Report Server after a data set returns data . The Options , which provides instructions on how to execute a query ( Time out ) or how to sort (collation, sensitivity) and interpret the subtotals Query is the only property available for access during runtime through the CommandText property of the DataSets collection. The rest of the properties are stored in Report Definition Language (RDL) and used by SSRS to process a data set. Command Type The command type is similar to the ADO.NET command type. It indicates the type of query that is contained in the query string and corresponding CommandText element of RDL. There are three values: Table , Text , and Stored Procedure . Text provides for execu- tion of a free-form (but, of course, valid) query. Stored Procedure corresponds to a stored procedure call. Finally Table indicates for SSRS to use the TableDirect feature of SQL From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. ptg 190 CHAPTER 11 Accessing Data Server, where the query is the name of a table from which to retrieve data. All data from the table is returned. NOTE Not all the providers support all three values. For example, whereas OLE DB supports the Table command type, the .NET provider MicrosoftSQLServer (SqlClient) does not. Therefore, Table is grayed out for the MicrosoftSQLServer (SqlClient) provider. Of course, SELECT * FROM <Table> would work just the same in the case of either provider. Parameters Most queries and stored procedures require inputting some type of parameter to return data. Consider the following example: SELECT * FROM Person.Address WHERE (City = @City) This is an example of a parameterized SQL on an Address table. Input parameters to stored procedures are another good example. So how does the data set give us this functionality? The answer is in the Parameters collection. To be clear, query parameters are separate from report parameters. Query parameters are used during the processing of the query, or SELECT statement. When you execute a query with a parameter in either of the designers, it will prompt you to enter its value (see Figure 11.6). If a query parameter is specified, a value must be given to the parameter for the query to process. A report parameter is used during report processing to show different aspects of the data that can include, but are not limited to, query processing. If a T-SQL query includes query parameters, the parameters are created in a report automatically, and the values specified in the report parameters are passed along to the query parameter. The Report Designer automatically creates a report parameter with the same name as the query parameter. If there is already a parameter with the same name, it associates the two parameters. Figure 11.7 shows the association and where it is located in the user interface. Note that when you click the fx button to expand [@City] you will see the following expression: =Parameters!City.Value . This is exactly the mapping between @City query parameter and report’s parameter City . After the Report Designer creates a report parameter, you will have to remove it from the set of report parameters manually. This is true even if you have removed the parameter From the Library of STEPHEN EISEMAN Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... the data source type Use a connection string that points to either the URL of a web service, web-based application, or XML document XML documents from inside SQLServer cannot be used Instead, use xquery or xpath as a part of the query with SQLServer as the data source type Use either Windows integrated security or no credentials No other type of credentials is supported The result of the query must... 5 Select Microsoft SQLServer 6 Enter the following connection string: Data Source=(localhost);Initial Catalog=AdventureWorks 7 On the Credentials tab, select the Use This User Name and Password option and enter the username and password This option allows the report to run unattended with the database credentials that you specified The credentials will be encrypted and stored in the ReportServer database... resultset that the rendering engine takes and uses to process the report Data sources can be either specific to a report or shared among many reports A number of data providers are installed with SQL Server and include SQL Server, SSAS, Oracle, XML, Teradata, SAP, and Essbase Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark From the Library of STEPHEN EISEMAN 196 CHAPTER 11 Accessing... SSRS 2000 release For instance, take a look at the list of report items in the Toolbox window of SQL Server Business Intelligence Development Studio (BIDS) The only new report item in the Toolbox window is Gauge However, Microsoft has made substantial changes to the inner working of report items For example, Microsoft has added the Tablix report item Tablix, although not available for picking from the... by “ & Parameters!Emphasis.Value You could also declare this in a custom code block: Function fnGetSql(Byval parameter as String) as String Return “select * from test_tb order by “ & Parameters!Emphasis.Value End Function And call it like this: =Code.fnGetSql(Parameters!Emphasis.Value) NOTE To prevent a SQL injection attack, leverage available values for a parameter and restrict a user’s permissions... the WHERE clause in the SQL? The dilemma comes when you need to run canned queries, such as stored procedures, or if you cannot pass in the appropriate value to filter inside the SQL A word of caution comes with this, too: It is much easier to filter at the database level than at the client level Returning large data sets simply to filter it down to one or two rows on the Report Server is possible, but... SQL and report parameter association Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark From the Library of STEPHEN EISEMAN 192 CHAPTER 11 Accessing Data from a query However, the Report Designer will remove the association if the parameter is no longer present in the query Stored procedures can be executed by changing the command type to Stored Procedure and entering the SQL. .. this watermark From the Library of STEPHEN EISEMAN CHAPTER 12 Report Parameters IN THIS CHAPTER Setting Up Parameters Parameter Properties Data-Driven Parameters Expressions with Parameters Dynamic SQL with Parameters Report-level parameters can serve a number of functions, including the following: Manipulating report data Parameter Dependencies Using Multivalue Parameters Example of Using Multivalue... match the type specified here Because NET CLR is a strongly typed system, SSRS is too It returns an error if a string is passed in for what is supposed to be a number value For a Boolean value, the Report Server simply creates a radio button list with true/false as the only options Text (default), Integer, Date/Time, Boolean, Float Prompt String A friendly message to pass to the user who enters the parameter... default values They can be either data driven through the same mechanism or hard-coded within the RDL The label is the value displayed to the user, whereas the value is the value passed back to the Report Server For example, this is useful in a query parameter in which you want the user to select a familiar name from a drop-down list, yet the query expects the ID Expressions with Parameters Up to this point, . type, the .NET provider Microsoft SQL Server (SqlClient) does not. Therefore, Table is grayed out for the Microsoft SQL Server (SqlClient) provider. Of. use ** *Server to denote a name or an IP address of a server that hosts a data source. For example, SQLServer is the name of a server that hosts a SQL Server