gpt4 book ai didi

sql-server - 在 SQL Server 2014 中使用 sp_send_dbmail 出现一般失败

转载 作者:行者123 更新时间:2023-12-02 23:15:17 25 4
gpt4 key购买 nike

我正在尝试使用 sp_send_dbmail 通过 SQL Server 2014 中的 SQLAgent 作业发送查询结果。我相信我的 DBMail 配置文件设置正确,但运行此命令时:

exec msdb.dbo.sp_send_dbmail
@profile = 'TestProfile',
@recipients = 'testmail@gmail.com',
@subject = 'Test',
@query = 'SELECT id FROM TestTable',
@attach_query_result_as_file = 1,
@query_attachment_filename = 'TestValues.txt'

我收到以下错误消息:

Failed to initialize sqlcmd library with error number -2147467259.

谷歌搜索此错误消息没有找到任何有用的信息,可能是由于通用错误号所致。有人对这个错误消息有一些了解吗?

最佳答案

我发现尽管我的查询窗口(用于测试)和 SqlAgent 作业都指向我所需的数据库,但 sp_send_dbmail 似乎没有任何数据库上下文。我原来的帖子失败了,因为 SQL 不知道在哪里运行 SELECT * FROM TestTable 。修复方法是通过完全限定 @query 中的表来为 sp_send_dbmail 提供数据库上下文。参数:

@query = 'SELECT id FROM testDB.dbo.TestTable'

或者通过提供可选的 @execute_query_database参数:

@execute_query_database = 'testDB'

关于sql-server - 在 SQL Server 2014 中使用 sp_send_dbmail 出现一般失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29501341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com