Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (5.77 MB, 182 trang )
Part III: Reporting Services
byte[] result = null;
string reportPath = "/AdventureWorks 2008 Sample Reports/Product Line
Sales 2008";
string format = "MHTML";
string historyID = null;
string devInfo = @"
// Prepare report parameter.
ParameterValue[] parameters = new ParameterValue[3];
parameters[0].Name = "ProductCategory";
parameters[0].Value = "1";
parameters[1].Name = "ProductSubcategory";
parameters[1].Value = "2"; // June
parameters[2].Name = "ProductSubcategory";
parameters[2].Value = "3";
DataSourceCredentials[] credentials = null;
string showHideToggle = null;
string encoding;
string mimeType;
string extension;
Warning[] warnings = null;
ParameterValue[] reportHistoryParameters = null;
string[] streamIDs = null;
ExecutionInfo2 execInfo2 = new ExecutionInfo2();
ExecutionHeader execHeader = new ExecutionHeader();
ServerInfoHeader svrinfoHeader;
execHeader = rs.LoadReport2(null, reportPath, historyID, out
svrinfoHeader, out execInfo2);
rs.SetExecutionParameters2(execHeader, null, parameters, "en-us", out
execInfo2);
String SessionId = execInfo2.ExecutionID.ToString();
try
{
rs.Render(execHeader, null, format, devInfo, out result, out extension,
out mimeType, out encoding, out warnings, out streamIDs);
}
catch (Exception exp)
{
//Throw the exception.
throw (exp);
}
Reference
Microsoft SQL Server TechNet Forum Support Team | Part III
Reporting Services
103
Part III: Reporting Services
ReportExecution2005 Namespace:
http://msdn.microsoft.com/en-us/library/reportexecution2005.aspx
Applies to
SQL Server Reporting Services 2005
SQL Server Reporting Services 2008
SQL Server Reporting Services 2008 R2
How do I pass a multi-value parameter to a dataset while
using LIKE operator in the WHERE clause?
Answer
1. Run the following code in your database to create a table valued function
which will be used to split a string into a table.
CREATE FUNCTION [dbo].[fn_String_To_Table] (
@String VARCHAR(max),
@Delimeter char(1),
@TrimSpace bit )
RETURNS @Table TABLE ( [Val] VARCHAR(4000) )
AS
BEGIN
DECLARE @Val VARCHAR(4000)
WHILE LEN(@String) > 0
BEGIN
SET @Val = LEFT(@String,
ISNULL(NULLIF(CHARINDEX(@Delimeter, @String) - 1, -1),
LEN(@String)))
Microsoft SQL Server TechNet Forum Support Team | Part III
Reporting Services
104
Part III: Reporting Services
SET @String = SUBSTRING(@String,
ISNULL(NULLIF(CHARINDEX(@Delimeter, @String), 0),
LEN(@String)) + 1, LEN(@String))
IF @TrimSpace = 1 Set @Val = LTRIM(RTRIM(@Val))
INSERT INTO @Table ( [Val] )
VALUES ( @Val )
END
RETURN
END
2. In your repot, define a single valued and internal parameter called MPjoin,
then must set its default value using the expression
=Join(Parameters!rptParameter.Value,",").
3. Change your dataset query string like this:
SELECT T1.Col1,T1.Col2,T1.Title
FROM myTable T1 INNER JOIN fn_String_To_Table(@MPjoin,',',1) T2
ON T1.Title LIKE T2.Val+ '%'
4. Open the Dataset Properties, in the windows box, click Parameters to go to
the dataset Parameters page and make sure the @MPjoin value is from
@MPJoin or the expression =Join(Parameters!rptParameter.Value,",").
How do I preview a Subreport which is in another SSRS
project?
Answer
To preview the subreport, you have to first deploy your report project which
contains the subreport to your report server. If you choose "Go to Report" for
the subreport, you also need to deploy your main SSRS project to the report
server and then specify the relative path. In this scenario, the subreport's name
will not be displayed in the drop-down list of Select a report from the list when
you design the main report. You have to manually type in the relative subreport
path in the drop-down list. For example, your two SSRS projects are deployed to
the report server as following structure:
Microsoft SQL Server TechNet Forum Support Team | Part III
Reporting Services
105
Part III: Reporting Services
Then you can configure the subreport settings as follows:
1. On your main report, right-click the textbox you want to add an action, and
then select Text box Properties...button.
2. Switch to the Action tab, type in the relative report path in the drop-down
list of Select a report from the list, such as ../DemoTest2/Product Detail:
Microsoft SQL Server TechNet Forum Support Team | Part III
Reporting Services
106
Part III: Reporting Services
3. If the subreport has parameters, you can click the Add button to add
parameters into the parameter grid.
4. You need to hard code the Parameter Name in the Name drop-down list, as
these parameters are not contained in the name drop-down list.
5. In the Value drop-down list, select a value to pass to the subreport.
6. Repeat steps 3-5 to specify a value for each subreport parameter.
7. Click OK.
8. Deploy the report project and preview it.
This method applies to Sql Server Reporting Service2005, Sql Server Reporting
Service2008 and Sql Server Reporting Service2008 R2.
Microsoft SQL Server TechNet Forum Support Team | Part III
Reporting Services
107
Part III: Reporting Services
Walkthrough: How to list models from SQL Server Master
Data Services in a SQL Server Reporting Services (SSRS)
Answer
SQL Server Master Data Services (MDS) is a new feature in SQL Server 2008 R2. It
is the source of master data for an organization. To learn more information
about it, you can read “Master Data Services”. This article walks through the
steps of how to access the models of SQL MDS in a SSRS report. The points are
exposing the MDS web services and using XML data source type to access the
data from the web services.
Expose the MDS WCF services to using BasicHttpBinding
1. In order to consume MDS web services, you need to enable web services for
MDS first. For detailed steps, please refer to How to: Enable Web Services
(Master Data Services).
2. Open the web.config configuration file for the MDS web site with text editor.
By default, the file is host in C:\Program Files\Microsoft SQL Server\Master
Data Services\WebApplication
3. Add the BasicHttpBinding configurations to the bindings section of the
web.config file as follows:
maxReceivedMessageSize="2147483647">
maxBytesPerRead="2147483647" maxDepth="2147483647"
maxNameTableCharCount="2147483647"
maxStringContentLength="2147483647"/>
Microsoft SQL Server TechNet Forum Support Team | Part III
Reporting Services
108
Part III: Reporting Services
maxReceivedMessageSize="2147483647">
maxBytesPerRead="2147483647" maxDepth="2147483647"
maxNameTableCharCount="2147483647"
maxStringContentLength="2147483647"/>
4. Configure the service to use BasicHttpBinding
name="Microsoft.MasterDataServices.Services.Service">
bindingConfiguration="mdsBasicHttpBinding"
bindingNamespace="http://schemas.microsoft.com/sqlserver/masterda
taservices/2009/09"
contract="Microsoft.MasterDataServices.Services.ServiceContracts.
IService" />
Create a Shared Data Source or embedded Data Source that is using
XML data source type
Create a Shared Data Source
Microsoft SQL Server TechNet Forum Support Team | Part III
Reporting Services
109