Sql-server – Failed to insert records into table in different server using sql server agent

insertsql server

My idea is to insert records from a table into another one in different server using T-SQL.

I've made maintenance plan along with its job and found below error.

Executed as user: NT SERVICE\SQLSERVERAGENT. Login failed for user
'MANYAR\MIT-DB2$'. [SQLSTATE 28000] (Error 18456)Unable to open Step
output file. The step failed.

I suspect SQLSERVERAGENT from source server might not have permission in destination server. I've tried to execute the T-SQL script in query and the scripts work well.

Best Answer

I believe you are seeing two different errors on your history report.

  1. You should validate the step output file on the job step(s).
  2. You should validate the linked server permissions & authentication.

Recreating the step output error

Testing with a location that does not exist

Create a jobstep that tries to access a step output folder location that does not exist

Regular T-SQL job steps might report the error but not fail the job, I used a maintenance plan to force the failure here

enter image description here

Start the job

enter image description here

Resulting error:

Executed as user: AgentServiceAccount. Unable to open Step output file. The step failed.

Testing with insufficient permissions

enter image description here

The same error is returned when no permissions are granted

Executed as user: AgentServiceAccount. Unable to open Step output file. The step failed.


Recreating the linked server permission error in combination with the step output error

Create a linked server

enter image description here

Authenticate with a non existing login

enter image description here

Create a job and jobstep to select from the newly created linked server

enter image description here

Point to a non existing output file

enter image description here

With the final resulting error on job execution matching yours

Executed as user: AgentServiceAccount Login failed for user 'nonexistinglogin'. [SQLSTATE 28000] (Error 18456)Unable to open Step output file. The step failed.

Validate the job step output & the linked server permissions and authentication and you should be good to go.