本文介绍了将SQL Azure数据库导出到Blob-Start-AzureSqlDatabaseExport:无法将AzureStorageContainer转换为AzureStorageContainer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码在堆栈上找到,并且所有连接都是正确的.

I am using this code found on stack , and all connections are correct.

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

我收到此错误.我已经花了几个小时了.

I am getting this error. I have spent hours on this.

Start-AzureSqlDatabaseExport : Cannot bind parameter 'StorageContainer'. Cannot convert the 
"Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageContainer" value of type 
"Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageContainer" to type 
"Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageContainer".
At line:31 char:99
+ ... SqlConnectionContext $SqlContext -StorageContainer $Container -Databa ...
+                                                        ~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Start-AzureSqlDatabaseExport], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.WindowsAzure.Commands.SqlDatabase.Database.Cmdlet.StartAzureSqlDatabaseExport

我正在使用AzureRM 3.8.0

I am using AzureRM 3.8.0

推荐答案

根据您的描述和代码,如果要开始新的sqldatabase导出.建议您尝试以下代码.会很好用的.

According to your description and codes, If you want to start a new sqldatabase export.I suggest you could try below codes. It will work well.

$subscriptionId = "YOUR AZURE SUBSCRIPTION ID"

Login-AzureRmAccount
Set-AzureRmContext -SubscriptionId $subscriptionId

# Database to export
$DatabaseName = "DATABASE-NAME"
$ResourceGroupName = "RESOURCE-GROUP-NAME"
$ServerName = "SERVER-NAME"
$serverAdmin = "ADMIN-NAME"
$serverPassword = "ADMIN-PASSWORD" 
$securePassword = ConvertTo-SecureString -String $serverPassword -AsPlainText -Force
$creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $serverAdmin, $securePassword

# Generate a unique filename for the BACPAC
$bacpacFilename = $DatabaseName + (Get-Date).ToString("yyyyMMddHHmm") + ".bacpac"

# Storage account info for the BACPAC
$BaseStorageUri = "https://STORAGE-NAME.blob.core.windows.net/BLOB-CONTAINER-NAME/"
$BacpacUri = $BaseStorageUri + $bacpacFilename
$StorageKeytype = "StorageAccessKey"
$StorageKey = "YOUR STORAGE KEY"

$exportRequest = New-AzureRmSqlDatabaseExport -ResourceGroupName $ResourceGroupName -ServerName $ServerName `
  -DatabaseName $DatabaseName -StorageKeytype $StorageKeytype -StorageKey $StorageKey -StorageUri $BacpacUri `
  -AdministratorLogin $creds.UserName -AdministratorLoginPassword $creds.Password

$exportRequest

# Check status of the export
Get-AzureRmSqlDatabaseImportExportStatus -OperationStatusLink $exportRequest.OperationStatusLink

然后,您可以使用Get-AzureRmSqlDatabaseImportExportStatus查看详细信息,如下所示:

Then you could use Get-AzureRmSqlDatabaseImportExportStatus to see the details information, like below:

这篇关于将SQL Azure数据库导出到Blob-Start-AzureSqlDatabaseExport:无法将AzureStorageContainer转换为AzureStorageContainer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 07:06