将 SSIS 任务执行 SQL 任务与 sp_send_mail 结合使用
我有一个 SSIS 包,它循环遍历许多人,然后将一组链接作为附件附加到报告中。
这一切都可以在发送邮件任务中正常工作,直到达到 4,000 个字符的限制:(
所以我试图让它与执行 SQL 任务一起使用,使用 sp_send_mail
我首先尝试一些简单的操作,但我无法让它工作
Paramater :用户::strPersonName 方向:输入 数据类型:VarChar 大小:-1
SQL 语句 =
DECLARE @bodytext AS VARCHAR(200)
SET @bodytext = 'Good Morning' + ?
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Shoop',
@recipients = '[email protected]',
@subject = '1',
@body = @bodytext
我收到结果集未正确设置一般错误
有什么想法吗? :(
I have a SSIS package which loops through a number of people then attaches a set of links to reports as attachments.
This all works fine with the Send mail task until I hit the 4,000 character limit :(
So I am trying to get this to work with the Execute SQL task, using sp_send_mail
I am trying something simple first but I cannot get it to work
Paramater : User::strPersonName
Direction : Input
Data Type : VarChar
Size : -1
SQL Statement =
DECLARE @bodytext AS VARCHAR(200)
SET @bodytext = 'Good Morning' + ?
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Shoop',
@recipients = '[email protected]',
@subject = '1',
@body = @bodytext
I am getting the resultset not properly set up generic error
Any ideas? :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您仍然可以使用 SSIS 中的发送邮件任务,而不是使用 sp_send_mail。我相信您在填充消息时所讨论的 4000 个字符限制是在表达式上,而不是在变量本身上。如果您在发送邮件任务中使用 MessageSourceType 变量,则可以使用脚本任务来构建消息正文(允许您创建大于 4000 个字符的字符串)。
编辑:由于问题出在您的附件上,根据 http://technet.microsoft.com/en-us/library/ms140355.aspx ,您应该使用“?”作为 ADO 连接的参数标记和 ADO.NET 的“@”,但似乎您正在使用两者。
作为另一种选择,这里有一篇关于如何使用脚本任务和 .NET 发送电子邮件的博客。 http://www.mssqltips.com/sqlservertip/1753/sending-html-formatted-email-in-sql-server-using-the-ssis-script-task/
Instead of using sp_send_mail, you could still use the send mail task from SSIS. The 4000 character limit that I believe you are talking about, when populating your message, is on the expression, not on the variable itself. If you are using a MessageSourceType of variable in the send mail task, you can use the script task to build your message body (allowing you to create a string larger than 4000 characters).
Edit: Since the problem is with your attachments, I see one thing that could be a problem with the SQL for your Execute SQL task, according to http://technet.microsoft.com/en-us/library/ms140355.aspx , you should use "?" as the parameter marker for ADO connections and "@" for ADO.NET, but it seems like you're using both.
As another alternative, here's a blog on how to use the script task and .NET to send your email. http://www.mssqltips.com/sqlservertip/1753/sending-html-formatted-email-in-sql-server-using-the-ssis-script-task/
您不需要结果集,但如果需要,请确保在 SQL 任务的“常规”选项卡中正确设置它。根据我的理解,您只是传递参数数据而不返回任何内容,因此我认为您将其设置为单行而不是无。
You shoudn't need a result set, but if you do make sure it is set correctly in the General tab in the SQL Task. From my understanding you are just passing in parameter data and not returning anything, so I think you have it set to Single Row instead of None.