使用SSIS呈现SSRS报告失败

时间:2016-11-24 16:48:24

标签: c# web-services reporting-services ssis render

我使用了网上找到的示例代码:

    #region Namespaces
    using System;
    using System.Data;
    using Microsoft.SqlServer.Dts.Runtime;
    using System.Windows.Forms;
    using System.IO;
    using System.Web.Services.Protocols;
    using ST_8ca6d57caecf488aa42b0ae8ff74f91d.TestReportExecution2005;
    #endregion

    In the main function 

    // Initiating report execution properties
    ReportExecutionService rexec = new ReportExecutionService();
    rexec.Credentials = System.Net.CredentialCache.DefaultCredentials;
    rexec.Url = "<Your Report Server Web Service    URL>/ReportExecution2005.asmx";

    // Render arguments
    // Render format e.g. MHTML/HTML4.0/PDF/EXCEL/IMAGE/CSV
    byte[] result = null;
    string reportPath = "/TestRS/ProductReport";
    string format = "MHTML";
    string historyID = null;
    string devInfo = @"<deviceinfo><toolbar>False</toolbar></deviceinfo>";

    // Prepare report parameter.
    ParameterValue[] parameters = new ParameterValue[3];
    parameters[0] = new ParameterValue();
    parameters[0].Name = "DepartmentID";
    parameters[0].Value =                 Dts.Variables["User::DepartmentID"].Value.ToString();

    string encoding = null;
    string mimeType;
    string extension;
    Warning[] warnings = null;
    string[] streamIDs = null;

    ExecutionInfo execInfo = new ExecutionInfo();
    ExecutionHeader execHeader = new ExecutionHeader();

    rexec.ExecutionHeaderValue = execHeader;
    execInfo = rexec.LoadReport(reportPath, historyID);
    rexec.SetExecutionParameters(parameters, "en-us");

    try
    {
        result = rexec.Render(format, devInfo, out extension, out encoding,         out mimeType, out warnings, out streamIDs);
        execInfo = rexec.GetExecutionInfo();
    }
    catch (SoapException e)
    {
        Dts.Events.FireError(0, "report rendering", e.Message, "\r" +         e.StackTrace, String.Empty, 0);
        Dts.TaskResult = (int)ScriptResults.Failure;
    }

    //Write the contents of the report to a mht/html/pdf/csv/xlsx/tiff file         to be attached in the email
    string reportFile = "ProductListing.mht";
    try
    {
        FileStream stream = File.Create(reportFile, result.Length);
        stream.Write(result, 0, result.Length);
        stream.Close();

        Dts.TaskResult = (int)ScriptResults.Success;
    }
    catch (Exception e)
    {
        Dts.Events.FireError(0, "saving report file", e.Message, "\r" +         e.StackTrace, String.Empty, 0);
        Dts.TaskResult = (int)ScriptResults.Failure;
    }
    //passing the filename for later attachment
    Dts.Variables["User::ReportFile"].Value = reportFile;  

在尝试添加Web引用时,代码编译失败。我按照建议添加了它作为一个简单的参考。

现在代码编译了,一旦尝试渲染报告'我得到的结果仍为null。无论我使用哪种报告。

使用SqlServer 2012

为什么添加Web引用中断编译? 为什么绕过它后,渲染什么都不做?

请帮忙

0 个答案:

没有答案