PowerShell New-AzSqlDatabaseImport - 0: The storage account cannot be accessed. Please check the storage account name and key and try again

Viewed 460

I've written a PowerShell script that copies a local bacpac file to an Azure storage account container. After the bacpac file has been copied from the local file system to the Azure blob container, I provide the storage account key and URI to the bacpac file to the New-AzSqlDatabaseImport command.

However, it never succeeds. I always get a 0: The storage account cannot be accessed. Please check the storage account name and key and try again error message. Unfortunately, no matter what I've tried, I cannot get it to work, and that error message isn't very descriptive or helpful at all. In the details response, I see severity "16" code "0" and the message of "The storage account cannot be accessed. Please check the storage account name and key and try again."

Does the -ResourceGroupName for the New-AzSqlDatabaseImport have to contain both the SQL server and the storage account? What permissions need to be enabled in order to allow the New-AzSqlDatabaseImport command to successfully access the storage account?

I do not understand what I'm doing wrong. I use the same key for the Set-AzStorageBlobContent command which works without a problem, so I know the key is correct. The URI to the bacpac file is correct as well. So what am I doing incorrectly? Does it matter that the Resource Group Name is not the same for the storage account and SQL server instance? Is there something in the firewall for the storage account I need to change?

Any help is appreciated!

1 Answers

We have tested in local environment by using the below cmdlet we can successfully import SQL database & below statements are based on our analysis.

  New-AzSqlDatabaseImport -ResourceGroupName "<resourceGroupName>" -ServerName "bacapserverdb" -DatabaseName "<DatabaseName>" -StorageKeyType "StorageAccessKey" -StorageKey "<storageAccountKey>" -StorageUri "<bacpacFileUri" -AdministratorLogin "<SQLServerUserName>" -AdministratorLoginPassword $SecureString -Edition Standard -ServiceObjectiveName S0 -DatabaseMaxSizeBytes 1073741824

Reference the below screenshot to pull Access key for a storage account from Azure portal.

Does the -ResourceGroupName for the New-AzSqlDatabaseImport have to contain both the SQL server and the storage account?

You need to pass the ResourceGroupName of the SQL database only as mentioned in the documentation.

What permissions need to be enabled in order to allow the New-AzSqlDatabaseImport command to successfully access the storage account?

You don't require any special permissions explicitly as you are passing the storage account Access key as a part of New-AzSqlDatabaseImport cmdlet.

Does it matter that the Resource Group Name is not the same for the storage account and SQL server instance?

As you are passing the resource group Name of the SQL database for the New-AzSqlDatabaseImport command. as per my understanding even if both the resources are in different resource group this operation can be succeeded.

Is there something in the firewall for the storage account I need to change?

When i have tested in our local environment we haven't applied any changes to firewall settings on the storage account.

Here is the sample output post successfully importing the sql database.

Limitations for Import \Exporting SQL Database :

  • Import Export Service does not work when Allow access to Azure services is set to OFF.
  • Import does not support specifying a backup storage redundancy while creating a new database and creates with the default geo-redundant backup storage redundancy. To workaround, first create an empty database with desired backup storage redundancy using Azure portal or PowerShell and then import the BACPAC into this empty database.
Related