SQL Server在电子邮件通知上的职位错误
我已经在SQL托管实例上配置了数据库电子邮件,运营商等,以在作业失败时接收电子邮件。
在电子邮件中,我们得到了这样的东西“ yyy_job在步骤3上失败”。
但是我的问题是... 有没有办法在电子邮件正文上添加错误消息? 我一直在搜索此信息一个合适的答案。
先感谢您
I have configured a database email, operators, and such on my SQL managed instance, to receive an email when a job fails.
In the email, we get something like this "The yyy_job failed on step 3".
But my question is... Is there a way to add the error message on the body of the email? I've been searching for this, but can't fine a suitable answer.
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,当作业失败时,没有办法在电子邮件通知中添加更多详细信息。
唯一的方法是实施您自己的通知过程。
https://www.sqlshack.com /在job-failure-in-in-in-sql-server/上报告和宣传
As far as I know there's no way to add further details to the email notifications when a job fails.
The only way is to implement your own notification process.
https://www.sqlshack.com/reporting-and-alerting-on-job-failure-in-sql-server/
我们有类似的设置。我们有一个由几个步骤组成的SQL Server代理作业。
我以这样的方式进行了配置,使我们在作业启动时会收到通知电子邮件,并在完成另一封电子邮件完成后。最终电子邮件有两个版本 - 一个是成功的,另一个用于失败。
在工作结束时,有两个最后的步骤称为“电子邮件确定”和“电子邮件失败”。请注意,每个步骤如何具有“成功”和“失败”配置。
在我们的情况下,这就是“电子邮件确定”和“电子邮件失败”的步骤的样子:
在我的情况下,我只是有不同的电子邮件主题,因此很容易过滤,因此电子邮件客户端。
您可以编写任何额外的T-SQL代码来针对
msdb.dbo.sysjobhistory
执行查询,并将相关结果包括在电子邮件中。我不会在这里写一个完整的查询,但我想它看起来与下面的草图相似。如果您需要帮助,请提出另一个问题。
这就是您可以使用
msdb.dbo.sp_send_dbmail
在电子邮件文本中包括一些查询的结果:请查看文档以获取文档以获取文档的列表
sp_send_dbmail
的参数。上面的示例嵌入了查询结果。您也可以将其作为单独的文件附加。We have a similar set up. We have a SQL Server Agent job that consists of several steps.
I configured it in such a way that we receive notification email when the job starts and another email when it finishes. There are two versions of the final email - one for success, another for failure.
At the end of the job there are two final steps called "Email OK" and "Email FAIL". Note how each of the steps have their "On Success" and "On Failure" configured.
This is how "Email OK" and "Email FAIL" steps look like in our case:
In my case I simply have different subjects of the emails, so it is easy to filter in the email client.
You can write any extra T-SQL code to execute a query against
msdb.dbo.sysjobhistory
and include the relevant result into the email.I will not write a complete query here, but I imagine it would look similar to my sketch below. If you need help with that, ask another question.
This is how you can use
msdb.dbo.sp_send_dbmail
to include the result of some query into the email text:Have a look at the documentation for a list of parameters for
sp_send_dbmail
. Example above inlines the query result. You can also attach it as a separate file.