There are usual errors when using a LINK Server while also using a Service account on SQL Job. Usual errors are as follows:
- Access to the Remote Server is Denied Because the Current Security Context is not Trusted
- EXECUTE AS USER failed for the requested [user] dbo in the [database]
- After resolving those 2 issue its still failed
Assumptions of your setup:
- You have created a credential object under Security > Credentials
- You have created a proxy that is using that credential under SQL Server Agent > Proxies > Operating System (CmdExec)
Here are the steps you need to do:
- Change database TRUSTWORTY to ON
ALTER DATABASE SQLDB0 SET TRUSTWORTHY ON
GO - Reapply database owner. This is needed because the SID recorded is now mismatch. c/o Rob Reid on this post.
ALTER AUTHORIZATION ON Database::[database] TO [domain\user]
- Update your SQL Job step to use CmdExec instead of T-SQL
Job Step Properties
– Type: Operating system (CmdExec)
– Run as: Your service account credentials using a proxy
– CommandSQLCMD -I -b -S $(ESCAPE_DQUOTE(SRVR)) -d DatabaseName -Q"EXEC usp_YourStoredProcedure"