Start-AzureSqlDatabaseExport: object reference not set to object instance

I am trying to start exporting an Azure SQL database to blob. However, having tried various approaches and searches on the Internet, I cannot find a way to make it work.

$exportRequest = Start-AzureSqlDatabaseExport -SqlConnectionContext $SqlContext -StorageContainer $Container -DatabaseName 'Users' -BlobName 'autobackupotest.bacpac' -Verbose -Debug  

The above line results in:

DEBUG: 2:05:14 PM - StartAzureSqlDatabaseExport begin processing with ParameterSet 'ByContainerObject'.
WARNING: Client Session Id: '111746f6-65c2-4ba1-b7c6-52a9171ee6-2016-03-28 08:15:58Z'
WARNING: Client Request Id: 'f20b3326-a6c4-48d7-beb0-6ce7b17585-2016-03-28 11:05:14Z'
Start-AzureSqlDatabaseExport : Object reference not set to an instance of an object.
At C:\tests\thirdversion.ps1:29 char:22
+     $exportRequest = Start-AzureSqlDatabaseExport -SqlConnectionContext $SqlCont ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Start-AzureSqlDatabaseExport], NullReferenceException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.SqlDatabase.Database.Cmdlet.StartAzureSqlDatabaseExport

DEBUG: 2:05:19 PM - StartAzureSqlDatabaseExport end processing.  

I checked the variables that I use for this cmdlet and they are not null. Prior to this cmdlet, I use the following code:

Import-Module Azure 
Import-Module Azure.Storage

Get-AzureRmSubscription –SubscriptionName "Production" | Select-AzureRmSubscription

# Username for Azure SQL Database server
$ServerLogin = "username"

# Password for Azure SQL Database server
$serverPassword = ConvertTo-SecureString "abcd" -AsPlainText -Force


# Establish credentials for Azure SQL Database Server 
$ServerCredential = new-object System.Management.Automation.PSCredential($ServerLogin, $serverPassword) 

# Create connection context for Azure SQL Database server
$SqlContext = New-AzureSqlDatabaseServerContext -FullyQualifiedServerName "myspecialsqlserver.database.windows.net" -Credential $ServerCredential

$StorageContext = New-AzureStorageContext -StorageAccountName 'prodwad' -StorageAccountKey 'xxxxx'
$Container = Get-AzureStorageContainer -Name 'automateddbbackups' -Context $StorageContext

$exportRequest = Start-AzureSqlDatabaseExport -SqlConnectionContext $SqlContext -StorageContainer $Container -DatabaseName 'Users' -BlobName 'autobackupotest.bacpac' -Verbose -Debug  

What could be wrong here? This exception message does not provide any details.

0
source share
1 answer

I checked your code and it works great on my side.

Login-AzureRmAccount Get-AzureRmSubscription –SubscriptionName "Production" | Select-AzureRmSubscription, , . , SQL-, StorageAccount, StorageAccountKey, ContainerName, .

+2

Source: https://habr.com/ru/post/1675861/


All Articles