automatic run scheduled reports with different parameters

  • Hi, I have got a question regarding the reporting services.

    I have got a report to run every day for different customers. I have set up customer as a parameter and running ok. My question is how to change the parameter automatically in a loop or something like that and run the report. Or I have to create hundreds of subscriptions and set up parameter individually?

    Thanks

    dxu

  • You may try something like this:

    // Get the report execution service.

    ReportExecution2005.ReportExecutionService res;

    try

    {

    res = new ReportExecution2005.ReportExecutionService()

    {

    Url = "http://MySSRS/reportserver/ReportExecution2005.asmx",

    Credentials = System.Net.CredentialCache.DefaultCredentials

    };

    }

    catch ( Exception ex )

    {

    // handle error

    }

    // Get the list of customers.

    // (This will probably come from a datatabase.

    Var customers = new List<string>()

    {

    // your list of customers

    }

    // Render reports.

    foreach ( var customer in customers )

    {

    var path = "http://MySSRS/..."; // your fully qualified name of the report

    try

    {

    res.ExecutionHeaderValue = new ExecutionHeader();

    res.LoadReport(path, null); // null: HistoryId

    }

    // If the load failed, we cannot process this report.

    catch ( SoapException e )

    {

    // handle SoapException

    }

    catch ( Exception e )

    {

    // handle GeneralException

    }

    // Parameters are passed as an array.

    // We create them as a listand convert them to array later.

    var parameters = new List<ParameterValue>();

    var parameter = new ParameterValue();

    parameter.Name = 'customer'; // perhaps

    parameter.Value = customer;

    parameters.Add( parameter );

    // Add any other parameters, as needed

    res.SetExecutionParameters( parameters.ToArray(), "en-us" );

    try

    {

    // out parameters:

    string extension, encoding, mimeType;

    Warning[] warnings;

    string[] streamIDs;

    res.Render( "MHTML",

    @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>",

    out extension,

    out encoding,

    out mimeType,

    out warnings,

    out streamIDs );

    // Possibly interesting: res.GetExecutionInfo()

    }

    catch ( SoapException e )

    {

    // handle SoapException

    }

    catch ( Exception e )

    {

    // handle GeneralException

    }

    } // foreach

    This of course assumes that all caching parameters on the report are already set.

    Good luck.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply