【发布时间】:2012-12-14 08:07:45
【问题描述】:
我有一份报告,其中显示了每天运行的进程中的所有错误(如果有的话)。
在流程结束时,我想编写一些代码来执行报告并通过电子邮件发送。我正在了解如何从代码通过电子邮件发送报告,但我似乎找不到任何显示如何从代码运行报告的地方。
我在 vs 08 中使用 C#,报告来自 ssrs 08。任何帮助将不胜感激!
【问题讨论】:
我有一份报告,其中显示了每天运行的进程中的所有错误(如果有的话)。
在流程结束时,我想编写一些代码来执行报告并通过电子邮件发送。我正在了解如何从代码通过电子邮件发送报告,但我似乎找不到任何显示如何从代码运行报告的地方。
我在 vs 08 中使用 C#,报告来自 ssrs 08。任何帮助将不胜感激!
【问题讨论】:
这是一些将报告呈现为字节的 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,请致电 Reporting Service web server(不是报告经理),然后通过电子邮件发送。
【讨论】:
我最终为创建工作的报告创建了一个新订阅。 我从执行作业的代码运行作业(取自 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();
通过调用作为订阅的作业 - 报告已呈现并通过电子邮件发送给订阅收件人。
【讨论】: