如何在天蓝色的弹性工作中修复 'Data structures for shard map manager persistence do not exist at the target location.'

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

我有一个应用程序使用多租户模型,每个租户一个数据库。我使用 Shardmap 来跟踪租户数据库的位置。 当我尝试为 运行 迁移创建一个弹性作业时,我将 AzSqlElasticJobTarget 设置为我的分片图数据库,所有 运行 都很好并且作业被创建但随后作业失败并且我收到以下错误:

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.

我已经去了数据库,上面有一个 __ShardManagement Scheme,里面有碎片的所有信息。

# 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

我终于发现用于访问租户目录的用户没有适当的 GRANT 来访问 SCHEMA::__ShardManagement,我的坏笑