链接服务器在 SQL 服务器作业上失败

Linked Server failing on SQL Server job

我有一个链接服务器,在执行查询时可以完美运行。但是当我将查询放入作业时,它失败了。

这是我的链接服务器的设置

错误

阅读SQL Server Agent job fails when the job uses a linked server

WORKAROUND To work around this problem, use one of the following methods:

Method 1

Make the system administrator the owner of the job.

Method2:

Use mapped security context for the linked server and modify the job to run as OSQL.

To set the mapped security context for the linked server: Right-click the linked server, and then click Properties. Click the Security tab. Select either of the following options. Be made using the login's current security context Be made using this security context To modify the job to run as OSQL: Right-click the job, and then click Properties. In the Steps tab, click the Step Name that you want to edit, and then click Edit. On the General tab of the Edit Job Step dialog box, click Operating System Command (CmdExec) in the Type list. In the Command text box, type osql –E –Q “Exec storedProcedure”. In the Edit Job Step dialog box, click OK. In the Properties dialog box, click OK.

在链接服务器定义中勾选: Be made using the login's current security context

我遇到了同样的问题,在更改用户权限等之后,我找到了这篇文章,而不是使用 "Be made using the login's current security context" 我使用了 "Be made using this security context" 并且我指定了解决问题的帐户和密码问题。所以问题不在于 SQL 作业或我的程序,实际上是我的 linked 服务器。尽管 link 服务器确实工作了...在 SQL 作业中调用 linked 服务器时,linked 服务器必须明确指定帐户详细信息。