代码改变世界

The server principal "sa" is not able to access the database "xxxx" under the current security context

2017-03-07 17:30  潇湘隐者  阅读(4467)  评论(1编辑  收藏  举报

在SQL Server服务器上一个作业执行时,遇到下面错误信息:

Message:

Executed as user: dbo. The server principal "sa" is not able to access the database "xxxx" under the current security context. [SQLSTATE 08004] (Error 916). The step failed.

clipboard

 

作业本身执行的存储过程非常简单,就是将数据库A中的历史数据处理过后,归档到A_History库中,结果就遇到这么一个问题。将作业的存储过程取出在SSMS客户端执行成功,没有问题,但是作业执行就遇到这个从我。后面折腾了一下,终于弄清楚了原委。 原来这个作业步骤的“Advanced”选项里面,设置成了Run as user 为dbo。

clipboard[1]

 

取消这个选项,问题即可解决。个人设置作业时从不设置此选项,但是有一些开发人员创建的作业就设置了此处选项,结果遇到了这个问题。

 

另外。我这篇博客SQL Agent Job 报“Access to the remote server is denied because the current security context is not trusted”里面遇到的其实也是这个问题。可笑当时虽然解决了,阴错阳差的解决了问题,但是还是没有找到Root Cause。 以此为戒!