链接服务器 - 拒绝访问远程服务器

Linked Server - Access to the remote server is denied

我在网上搜索了 Sql 服务器代理作业 运行 针对远程数据库返回的错误的答案,但无法让它工作。错误是:

    Msg 15274, Sev 16, State 1, Line 1 : 
    Access to the remote server is denied because the current security context is not trusted. [SQLSTATE 42000]

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

    EXEC sp_addlinkedserver @server=N'serverName' 
       , @srvproduct=N''
       , @provider=N'SQLNCLI'
       , @datasrc=N'serverName';

同样地运行:

    EXEC sp_addlinkedsrvlogin  @rmtsrvname = N'serverName'
       , @useself = false
       , @locallogin = NULL
       , @rmtuser = 'sa'
       , @rmtpassword = 'userpassword'

当我执行 EXEC [ServerName].[DbName].[SchemaName].[StoredProcName] 时,我成功返回值,但在 Sql 代理作业中相同的查询失败。我必须做什么才能让 Agent Job 工作?

参见this

总之,好像是这样的:

When you run a SQL Server Agent job that is not owned by a system administrator account, SQL Server Agent runs SETUSER to impersonate the owner of the job.

If the job uses linked servers, the job may fail because remote access is not allowed after the execution of SETUSER.

因此,要么将作业的所有权更改为 sysadmin acc,要么将链接服务器映射更改为例如使用模拟。我没有看到任何其他选项。