运行 ssrs 报告并通过 .net 代码通过电子邮件发送

发布于 2024-09-10 20:40:50 字数 162 浏览 3 评论 0原文

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

I have a report that shows all errors (if there are any) from a process that runs every day.
At the end of the process, I want to write some code to execute the report and email it. I am seeing how to email a report from code, but I can't seem to find anywhere that shows how to run the report from code.
I am using C# in vs 08, and the report is from ssrs 08. Any assistance would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

九八野马 2024-09-17 20:40:50

下面是一些将报告渲染为字节的 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 代码。

Here is some vb code to render the report into bytes:

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

this shows the basic stuff for rendering a report in code. VS 2005 code.

日暮斜阳 2024-09-17 20:40:50

如果您不使用 ReportViewer,请调用 报告服务网络服务器不是报告管理器),然后通过电子邮件发送。

if you aren't using ReportViewer, then call the Reporting Service web server (not report manager), and then email it.

作死小能手 2024-09-17 20:40:50

我最终创建了一个新的订阅来创建一个作业的报告。
我通过执行作业的代码运行该作业(取自 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();

通过调用作业(这是一个订阅),报告被呈现并通过电子邮件发送给订阅收件人。

I ended up creating a new subscription to the report which creates a job.
I ran the job from code that executes the job(Taken from Microsoft)

Like this:

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();

By calling the job- which is a subscription - the report was rendered and emailed to the subscription recipients.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文