【问题标题】:run ssrs report and email it from .net code运行 ssrs 报告并从 .net 代码通过电子邮件发送
【发布时间】:2012-12-14 08:07:45
【问题描述】:

我有一份报告,其中显示了每天运行的进程中的所有错误(如果有的话)。
在流程结束时,我想编写一些代码来执行报告并通过电子邮件发送。我正在了解如何从代码通过电子邮件发送报告,但我似乎找不到任何显示如何从代码运行报告的地方。
我在 vs 08 中使用 C#,报告来自 ssrs 08。任何帮助将不胜感激!

【问题讨论】:

    标签: reporting-services report


    【解决方案1】:

    这是一些将报告呈现为字节的 vb 代码:

    Private Sub ExportReport(ByVal ReportViewer)
        reportType = "PDF"
        deviceInfo = "<DeviceInfo><OutputFormat>PDF</OutputFormat><PageWidth>8.5in</PageWidth><PageHeight>11in</PageHeight><MarginTop>0.5in</MarginTop><MarginLeft>0.5in</MarginLeft><MarginRight>0.5in</MarginRight><MarginBottom>0.5in</MarginBottom></DeviceInfo>"
        renderedBytes = ReportViewer.LocalReport.Render(reportType, deviceInfo, mimeType, Encoding, fileNameExtension, streams, warnings)
    End Sub
    
    
    Public Function CreateAttachment() As Attachment
        Dim MemStr As New MemoryStream(renderedBytes)
        Dim ContentType As New ContentType(mimeType)
        Dim pdf As New Attachment(MemStr, ContentType)
        pdf.Name = ReportName & "." & fileNameExtension
        Return pdf
    End Function
    

    这显示了在代码中呈现报告的基本内容。 VS 2005 代码。

    【讨论】:

    • 我看到您正在使用报告查看器。我没有用户界面 - 我需要知道如何在没有 reportViewer 的情况下呈现/调用报告。
    • 我以非可视方式使用报表查看器,只是为了呈现输出。您可以声明一个并在没有表单的情况下创建。 ssrs 报告是本地模式还是服务器模式报告?
    【解决方案2】:

    如果您不使用 ReportViewer,请致电 Reporting Service web server不是报告经理),然后通过电子邮件发送。

    【讨论】:

      【解决方案3】:

      我最终为创建工作的报告创建了一个新订阅。 我从执行作业的代码运行作业(取自 Microsoft)

      像这样:

      SqlConnection jobConnection;
              SqlCommand jobCommand;
              SqlParameter jobReturnValue;
              SqlParameter jobParameter;
              int jobResult;
      
              jobConnection = new SqlConnection("myconnectionstring");
              jobCommand = new SqlCommand("sp_start_job", jobConnection);
              jobCommand.CommandType = System.Data.CommandType.StoredProcedure;
      
              jobReturnValue = new SqlParameter("@RETURN_VALUE", SqlDbType.Int);
              jobReturnValue.Direction = ParameterDirection.ReturnValue;
              jobCommand.Parameters.Add(jobReturnValue);
      
              jobParameter = new SqlParameter("@job_name", SqlDbType.VarChar);
              jobParameter.Direction = ParameterDirection.Input;
              jobCommand.Parameters.Add(jobParameter);
              jobParameter.Value = "name of the subscription job";
              jobConnection.Open();
              jobCommand.ExecuteNonQuery();
              jobResult = (Int32)jobCommand.Parameters["@RETURN_VALUE"].Value;
              jobConnection.Close();
      
              switch (jobResult)
              {
                  case 0:
                      Console.WriteLine("SQL Server Agent job, RunSISSPackage, started successfully.");
                      break;
                  default:
                      Console.WriteLine("SQL Server Agent job, RunSISSPackage, failed to start.");
                      break;
              }
              Console.Read();
      

      通过调用作为订阅的作业 - 报告已呈现并通过电子邮件发送给订阅收件人。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-05-07
        • 2019-04-17
        • 1970-01-01
        • 2021-10-02
        • 2014-11-27
        • 2020-10-13
        • 2012-09-08
        • 1970-01-01
        相关资源
        最近更新 更多