1

I am trying to use powershell to create an Elastic Job. I can create the job using TSQL with no issues but when try to add a job step it gives error: 'Elastic jobs management operation failed. Cannot reference the credential 'JobExecuteUser', because it does not exist or you do not have permission.' I have not been able to google any occurrences of this error. I know the credential exists because I use the same values in my TSQL code. I am confident my parameter values are correct because I have used them to remove/create TargetGroups and TargetMembers and the job itself.

Here is the code:

Add-AzSqlElasticJobStep `
       -ResourceGroupName $ResourceGroupName `
       -ServerName $ServerName  `
       -AgentName $AgentName `
       -JobName $JobName `
       -TargetGroupName $TargetGroupName `
       -CredentialName $CredentialName `
       -Name "Deploy CommandLog"  `
       -CommandText "Do Nothing"    
Martin Cairney
  • 1,714
  • 1
  • 6
  • 18
deannich
  • 11
  • 1
  • 1
    What credentials are you connecting with from PowerShell? Is it an admin for the Job Database? – Martin Cairney Feb 18 '21 at 03:13
  • Yes I am an admin. It works in TSql which should be same perms. – deannich Feb 19 '21 at 13:46
  • The credential name it is looking for is not the SQL Credential name created when setting up the Elastic Job but the SQL User name the credential was set up for. – deannich Feb 20 '21 at 00:16
  • The ```CredentialName ``` parameter shold be the name of the credential that the Job will execute as, not the SQL User Name. For example if I create a Credential named "JobExec" which is created for the SQL User "JobUser" then the parameter value to use is "JobExec". The Job Agent and Azure SQL DB will do the context change so that the connection is then made with the "Jobuser" login whenever the connection is made to the target database. – Martin Cairney Feb 21 '21 at 23:25

0 Answers0