0

I have a stored procedure that I can execute in SSMS with a non domain SQL Server user.

This stored procedure selects data from tables in one database (DB1) truncates and selects into a table in DB2.

The user has datareader,datawriter and dbowner for both databases.

Problem:

When I execute the stored procedure via SS Agent with execute as the user I get the following error

The server principal [user] is not able to access the database [DB1] under the current security context.

Actions taken So far:

I have tried to resolve this so far by:

  1. Turning on db chaining for both databases
  2. Deleted the user from DB1 and added again
  3. Checked using EXEC sp_change_users_login @Action=’Report’ to see if user orphaned. As this is a database that is a restore of a live one. However I added the user after the restore. The user was not listed as orphaned
Peter Campbell
  • 661
  • 1
  • 7
  • 35

1 Answers1

1

A possible workaround if you don't want to have the owner be sa is to have the user be a member of msdb and grant the the SQLAgentOperatorRole in msdb. See if that works.

But to be honest, either use sa or a dedicated service account with enough permissions. It's better if the job runs under that context.

Charles Farr
  • 369
  • 3
  • 8