ReportingService2005.CreateDataDrivenSubscription Method (String, ExtensionSettings, DataRetrievalPlan, String, String, String, ParameterValueOrFieldReference[])


Creates a data-driven subscription for a specified report.

Namespace:   ReportService2005
Assembly:  ReportService2005 (in ReportService2005.dll)

public string CreateDataDrivenSubscription(
	string Report,
	ExtensionSettings ExtensionSettings,
	DataRetrievalPlan DataRetrievalPlan,
	string Description,
	string EventType,
	string MatchData,
	ParameterValueOrFieldReference[] Parameters


Type: System.String

The fully qualified URL of the report for which to create a data-driven subscription.

Type: ReportService2005.ExtensionSettings

An ExtensionSettings object that contains a list of settings that are specific to the delivery extension.

Type: ReportService2005.DataRetrievalPlan

A DataRetrievalPlan object that provides settings that are required to retrieve data from a delivery query. The DataRetrievalPlan object contains a reference to a DataSetDefinition object and a DataSourceDefinitionOrReference object.

Type: System.String

A meaningful description that is displayed to users.

Type: System.String

The type of event that triggers the data-driven subscription. The valid values are TimedSubscription or SnapshotUpdated.

Type: System.String

The data that is associated with the specified EventType parameter. This parameter is used by an event to match the data-driven subscription with an event that has fired.

Type: ReportService2005.ParameterValueOrFieldReference[]

An array of ParameterValueOrFieldReference objects that contains a list of parameters for the report.

Return Value

Type: System.String

A String value containing a subscription ID that uniquely identifies the data-driven subscription in the report server database.

The table below shows header and permissions information on this operation.

SOAP Headers

(In) BatchHeaderValue

(Out) ServerInfoHeaderValue

Required Permissions

ExecuteAndView AND CreateAnySubscription

The length of the Report parameter cannot exceed 260 characters; otherwise, a SOAP exception is thrown with the error code rsItemLengthExceeded.

The Report parameter cannot be null or empty or contain the following reserved characters: : ? ; @ & = + $ , \ * > < | . ". You can use the forward slash character (/) to separate items in the full path name of the folder, but you cannot use it at the end of the folder name.

You can use the GetExtensionSettings method to retrieve a list of the required settings for a delivery extension. You must pass values for these required settings in the ExtensionSettings parameter. For information about e-mail delivery settings, see Reporting Services Delivery Extension Settings.

The DataRetrievalPlan parameter takes a DataRetrievalPlan object as its argument. The DataRetrievalPlan object contains a dataset with a delivery query. The CommandType property of the delivery query (QueryDefinition object) is set to Text by default for data-driven subscriptions and does not have to be specified. If you specify a value for the CommandType property, the value must be Text.

The data source provided or referenced in the dataset for the delivery query must have a CredentialRetrieval setting of Store.

Values for delivery extension settings and parameters can be set to either static values or to field references. When a field reference is specified for delivery extension setting or a parameter, the value of the setting or parameter is data driven. The dataset with the delivery query has a set of fields (Field objects) that are mapped to delivery extension settings (ExtensionParameter objects) and report parameter values (ParameterValue objects). All fields referenced in delivery extension settings and report parameter values must correspond to the fields in the dataset. If the delivery query does not return a field that is specified in a delivery extension setting or a parameter value, the report server raises an error when the subscription is processed.

The value of the EventType parameter must correspond to an event that is configured for the report server. The two events that are used to create subscriptions are TimedSubscription and SnapshotUpdated. Use the ListEvents method to return a list of all events configured for the report server.

The value of the MatchData parameter depends on the event type. If the event is a TimedSubscription event, a ScheduleDefinition object is required as the MatchData parameter. You must first serialize the ScheduleDefinition object as XML in order to pass it as a string value and create a subscription based on the schedule. The XML structure might look like the one in the following example:


The value of the StartDateTime element when passed as an XML string should correspond to the date format ISO 8601. This international date and time standard is the extended format CCYY-MM-DDThh:mm:ss+/-Z where "CC" represents the century, "YY" the year, "MM" the month and "DD" the day. The letter "T" is the date and time separator and "hh", "mm", "ss" represent hour, minute and second, respectively. This representation may be immediately followed by a "Z" to indicate Coordinated Universal Time (UTC). To indicate the time zone, represented as the difference between the local time and Coordinated Universal Time, "Z" is preceded by a "+" or "-" sign, followed by the difference from UTC represented as hh:mm.

If the schedule definition for a TimedSubscription is a shared schedule, you must pass the schedule ID of the shared schedule as the MatchData parameter. The schedule ID is passed as a String, for example, "4608ac1b-fc75-4149-9e15-5a8b5781b843". The schedule ID can be obtained by calling the ListSchedules method.

You can use the XmlSerializer class to convert your object class to an XML string automatically. For more information about the XmlSerializer class, see "System.Xml.XmlSerializer Class" in the Microsoft .NET Framework documentation.

If the event is a SnapshotUpdated subscription, the value of MatchData should be null (or Nothing in Visual Basic).

Using this method sets the LastExecutedSpecified property of the subscription to none, the Status property of the subscription to new subscription, and all properties of the subscription’s Active object to false. The ModifiedBy and ModifiedDate properties of the report are also updated.

To compile this code example, you must reference the Reporting Services WSDL and import certain namespaces. For more information, see Compiling and Running Code Examples. The following code example uses CreateDataDrivenSubscription to add a new data-driven subscription to the report server database:

using System;
using System.Web.Services.Protocols;

class Sample
   public static void Main()
      ReportingService rs = new ReportingService2005();
      rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

      string report = "/SampleReports/Employee Sales Summary";
      string description = "My new data driven subscription";

      // Set the extension setting as report server email.
      ExtensionSettings settings = new ExtensionSettings();
      settings.Extension = "Report Server Email";

      // Set the extension parameter values.
      ParameterValueOrFieldReference[] extensionParams = 
         new ParameterValueOrFieldReference[8];

      ParameterFieldReference to = new ParameterFieldReference(); // Data-driven.
      to.ParameterName = "TO";
      to.FieldAlias = "EmailAddress"; 
      extensionParams[0] = to;

      ParameterValue replyTo = new ParameterValue();
      replyTo.Name = "ReplyTo";
      replyTo.Value ="";
      extensionParams[1] = replyTo;

      ParameterValue includeReport = new ParameterValue();
      includeReport.Name = "IncludeReport";
      includeReport.Value = "False";
      extensionParams[2] = includeReport;

      ParameterValue renderFormat = new ParameterValue();
      renderFormat.Name = "RenderFormat";
      renderFormat.Value = "HTML4.0";
      extensionParams[3] = renderFormat;

      ParameterValue priority = new ParameterValue();
      priority.Name = "Priority";
      priority.Value = "NORMAL";
      extensionParams[4] = priority;

      ParameterValue subject = new ParameterValue();
      subject.Name = "Subject";
      subject.Value = "Your sales report";
      extensionParams[5] = subject;

      ParameterValue comment = new ParameterValue();
      comment.Name = "Comment";
      comment.Value = "Here is the link to your report.";
      extensionParams[6] = comment;

      ParameterValue includeLink = new ParameterValue();
      includeLink.Name = "IncludeLink";
      includeLink.Value = "True";
      extensionParams[7] = includeLink;

      settings.ParameterValues = extensionParams;

      // Create the data source for the delivery query.
      DataSource delivery = new DataSource();
      delivery.Name = "";
      DataSourceDefinition dataSourceDefinition = new DataSourceDefinition();
      dataSourceDefinition.ConnectString = "data source=(local);initial catalog=Employee";
      dataSourceDefinition.CredentialRetrieval = CredentialRetrievalEnum.Store;
      dataSourceDefinition.Enabled = true;
      dataSourceDefinition.EnabledSpecified = true;
      dataSourceDefinition.Extension = "SQL";
      dataSourceDefinition.ImpersonateUserSpecified = false;
      dataSourceDefinition.UserName = "username";
      dataSourceDefinition.Password = "runUnAtt1";
      delivery.Item = dataSourceDefinition;

      // Create the fields list.
      Field[] fieldsList = new Field[2];
      fieldsList[0] = new Field();
      fieldsList[0].Name = "EmailAddress";
      fieldsList[0].Alias = "EmailAddress";
      fieldsList[1] = new Field();
      fieldsList[1].Name = "EmpID";
      fieldsList[1].Alias = "EmpID";

      // Create the data set for the delivery query.
      DataSetDefinition dataSetDefinition = new DataSetDefinition();
      dataSetDefinition.AccentSensitivitySpecified = false;
      dataSetDefinition.CaseSensitivitySpecified = false;
      dataSetDefinition.KanatypeSensitivitySpecified = false;
      dataSetDefinition.WidthSensitivitySpecified = false;
      dataSetDefinition.Fields = fieldsList;
      QueryDefinition queryDefinition = new QueryDefinition();
      queryDefinition.CommandText = "Select * from MailList";
      queryDefinition.CommandType = "Text";
      queryDefinition.Timeout = 45;
      queryDefinition.TimeoutSpecified = true;
      dataSetDefinition.Query = queryDefinition;
      DataSetDefinition results = new DataSetDefinition();
      bool changed;
      string[] paramNames;

         results = rs.PrepareQuery(delivery, dataSetDefinition, out changed, out paramNames);
      catch (SoapException e)

      DataRetrievalPlan dataRetrieval = new DataRetrievalPlan();
      dataRetrieval.DataSet = results;
      dataRetrieval.Item = dataSourceDefinition;
      // Set the event type and match data for the delivery.
      string eventType = "TimedSubscription";
      string matchData = "<ScheduleDefinition><StartDateTime>2003-04-14T19:15:00-07:00</StartDateTime><WeeklyRecurrence><WeeksInterval>1</WeeksInterval><DaysOfWeek><Monday>True</Monday><Tuesday>True</Tuesday><Wednesday>True</Wednesday><Thursday>True</Thursday><Friday>True</Friday></DaysOfWeek></WeeklyRecurrence></ScheduleDefinition>";

      // Set the report parameter values.
      ParameterValueOrFieldReference[] parameters = new ParameterValueOrFieldReference[3];

      ParameterFieldReference empID = new ParameterFieldReference(); // Data-driven.
      empID.ParameterName = "EmpID";
      empID.FieldAlias = "EmpID";
      parameters[0] = empID;

      ParameterValue reportYear = new ParameterValue();
      reportYear.Name = "ReportYear";
      reportYear.Value = "2004";
      parameters[1] = reportYear;

      ParameterValue reportMonth = new ParameterValue();
      reportMonth.Name = "ReportMonth";
      reportMonth.Value = "6"; // June
      parameters[2] = reportMonth;

         string subscriptionID = rs.CreateDataDrivenSubscription( 
   report, settings, dataRetrieval, description, eventType, matchData, parameters);
      catch (SoapException e)
Return to top