问题描述
我正在尝试开始将SQL Azure数据库导出到Blob.但是,在尝试了不同的方法并搜索了网络之后,我找不到找到使之工作的方法.
I am trying to start an export of a SQL Azure database to a blob. However, after trying different approaches and searching the web I can't find a way to make it work.
$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之前,我使用以下代码:
I verified the variables I use for this cmdlet and they are not null. Prior to that 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? That exception message does not provide any detail.
推荐答案
我测试了您的代码,它对我而言很好用.
I tested your code and it works fine on my side.
运行Login-AzureRmAccount
在Get-AzureRmSubscription –SubscriptionName Production | Select-AzureRmSubscription
之前登录,请验证当前租户中是否存在预订生产.并仔细检查SQL Server的用户名,密码,StorageAccount,StorageAccountKey,ContainerName是否正确.
Run Login-AzureRmAccount
to login before Get-AzureRmSubscription –SubscriptionName "Production" | Select-AzureRmSubscription
, verify that the subscription Production exists in current tenant. And double check the username,password for SQL server, StorageAccount,StorageAccountKey,ContainerName are all correct.
这篇关于Start-AzureSqlDatabaseExport:对象引用未设置为对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!