我正在尝试将SQL Azure数据库导出到blob。但是,在尝试不同的方法并搜索网络后,我无法找到一种方法使其发挥作用。
$exportRequest = Start-AzureSqlDatabaseExport -SqlConnectionContext $SqlContext -StorageContainer $Container -DatabaseName 'Users' -BlobName 'autobackupotest.bacpac' -Verbose -Debug
上面的行导致:
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.
我验证了我用于此cmdlet的变量,它们不是null。在该cmdlet之前,我使用以下代码:
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
这里有什么问题?该异常消息不提供任何细节。
答案 0 :(得分:2)
我测试了你的代码,它在我身边很好用。
运行Login-AzureRmAccount
以在Get-AzureRmSubscription –SubscriptionName “Production” | Select-AzureRmSubscription
之前登录,验证当前租户中是否存在订阅生产。并仔细检查SQL Server,StorageAccount,StorageAccountKey,ContainerName的用户名,密码是否正确。