4

When I'm trying to fetch DB in elastic pool getting error as:

The Resource 'Microsoft.Sql/servers/dbserver.database.windows.net/databases/db_name' under resource group 'rg_name' was not found.

But for other DB servers and resource group, this script works.

The script I'm trying:

Import-Module Az.Accounts
Import-Module Az.Sql

#Connect-AzAccount -SubscriptionId $subscriptionId
$passwd = ConvertTo-SecureString <PASSWORD> -AsPlainText -Force
$pscredential = New-Object System.Management.Automation.PSCredential('<Application ID>/<Service Principle ID>', $passwd)
Connect-AzAccount -ServicePrincipal -Credential $pscredential -Tenant $tenantId 
#-SubscriptionId $subscriptionId

$rg = Get-AzResourceGroup -Name $resourceGroupName

Set-AzSqlDatabase -DatabaseName $DatabaseName -ElasticPoolName $PoolName -ResourceGroupName $rg.ResourceGroupName -ServerName $serverName 

Read-Host -Prompt "Press Enter to exit "

I verified the permissions, resources and their names/ids all are correct.

Mahesh Waghmare
  • 726
  • 9
  • 27
Akash Samal
  • 87
  • 1
  • 9
  • fairly certain that the id is invalid, as the sql server id isnt its dns name – 4c74356b41 Sep 18 '19 at 06:40
  • I'm not using SQL Server ID anywhere, just using DNS name. Which worked for my another subscription – Akash Samal Sep 18 '19 at 06:44
  • Have you tried to get the database with PowerShell? – Jim Xu Sep 18 '19 at 06:52
  • And is that you want to add the database to the elastic pool ? – Jim Xu Sep 18 '19 at 06:58
  • Yes, I would like to add a database to an elastic pool – Akash Samal Sep 18 '19 at 07:05
  • Could you please try to use the following script ```$dt = Get-AzSqlDatabase -DatabaseName $DatabaseName -ServerName $serverName -ResourceGroupName $groupName Set-AzSqlDatabase -DatabaseName $dt.DatabaseName -ElasticPoolName testpool -ServerName $dt.ServerName -ResourceGroupName $dt.ResourceGroupName``` to implement it? – Jim Xu Sep 18 '19 at 07:43
  • Tried using above script but still same error. No change. – Akash Samal Sep 18 '19 at 09:04
  • Could you tell me if you can run the command ```Get-AzSqlDatabase -DatabaseName $DatabaseName -ServerName $serverName -ResourceGroupName $groupName```? – Jim Xu Sep 18 '19 at 09:34
  • I could not run above command getting same error as mentioned in the question. – Akash Samal Sep 18 '19 at 10:39

1 Answers1

12

According to the error message, I can see that you are providing the -ServerName as dbserver.database.windows.net

Please provide the -ServerName as only dbserver instead of dbserver.database.windows.net

AmanGarg-MSFT
  • 1,123
  • 6
  • 10
  • Thank you for this! Maddening when the error is telling me the server isn't in the resource group, and it obviously IS in the resource group! – Brian Stork Jan 31 '20 at 19:09