How to fix 'Data structures for shard map manager persistence do not exist at the target location.' in azure elastic jobs

I have an app that uses multitenancy un a single db per tenant model. I use a Shardmap to keep track of where the tenent db is located. When I tried to create an elastic job to run the migrations I set the AzSqlElasticJobTarget to my shardmap db, all runs well and the job gets created but then the job fails and i get the following error:

Failed to determine members of SqlShardMapTarget (server name '***', server location '***.database.windows.net', database '***', shard map '***'): Data structures for shard map manager persistence do not exist at the target location.

I already went to the db and there is a __ShardManagement Scheme on it, with all the info of the shards.

# Create TenantsPoolGroup target group
$TenantsGroup = $JobAgent | New-AzSqlElasticJobTargetGroup -Name 'TargetGroup'
$TenantsGroup | Add-AzSqlElasticJobTarget -ServerName $catalogServerName -ShardMapName $config.CatalogShardMapName -DatabaseName $config.CatalogDatabaseName -RefreshCredentialName $config.JobCredentialName

Write-Output "Creating a new job"
$timestamp = Get-Date -Format o | foreach {$_ -replace ":", "_"}
$timestamp = $timestamp | foreach {$_ -replace "\.", "_"}
$timestamp = $timestamp | foreach {$_ -replace "-", "_"}
$JobName = "Migration-$timestamp"
$Job = $JobAgent | New-AzSqlElasticJob -Name $JobName -RunOnce

Write-Output "Creating job steps"
$SqlText = Get-Content -Path "$PSScriptRoot\script-entities.sql" -Raw
$Job | Add-AzSqlElasticJobStep -Name "step1" -TargetGroupName 'TargetGroup' -CredentialName $config.JobCredentialName -CommandText $SqlText

Write-Output "Start a new execution of the job..."
$JobExecution = $Job | Start-AzSqlElasticJob

Upvotes: 0

Views: 322

Answers (1)

I finally found that the user being used to access the tenants catalog didn't had the propper GRANT to be able to access the SCHEMA::__ShardManagement, lol my bad

Upvotes: 1

Related Questions