Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linked Server failing on SQL Server job

I have a linked server that perfectly works when executing a query. But when I place the query in a job, it fails.

Here is the setting of my linked server

setting

Error

error enter image description here

like image 662
Philip Morris Avatar asked Sep 09 '15 10:09

Philip Morris


2 Answers

Read 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.

In linked server definition tick: Be made using the login's current security context

like image 93
Lukasz Szozda Avatar answered Sep 28 '22 20:09

Lukasz Szozda


I had this same issue, And after changing user permissions etc etc etc, I found this article and instead of using "Be made using the login's current security context" i used "Be made using this security context" and i specified the account and password which solved the issue. So the issue isnt with SQL jobs or my procedure it was in actual fact my linked server. Even though the link server did work... When calling a linked server within a SQL job the linked server had to have the account details specifically specified.

like image 45
Jay Avatar answered Sep 28 '22 20:09

Jay