【问题标题】:Connecting to Azure SQL Database via Powershell通过 Powershell 连接到 Azure SQL 数据库
【发布时间】:2016-06-02 12:31:23
【问题描述】:

我试图让 powershell 从本地连接到 Azure SQL 数据库。我尝试了以下sn-p

$params = @{
  'Database' = 'dbsitenamehere'
  'ServerInstance' =  'instancename.database.windows.net'
  'Username' = 'abcites'
  'Password' = 'atbasIcpr0d'
  'OutputSqlErrors' = $true
  'Query' = 'SELECT * FROM Users'
 }
 Invoke-Sqlcmd  @params

但我收到了这个警告:

警告:无法获取 SQL Server 服务信息。尝试连接到“Microsoft.WindowsAzure.Commands.SqlDatabase.Types.ps1xml”上的 WMI 失败,出现以下错误:RPC 服务器不可用。 (HRESULT 异常:0x800706BA)

我认为,通过手动打开组件服务链接中的 RPC 定位器服务来解决上述问题,由 Hodentek @http://hodentekmsss.blogspot.in/2014/11/how-to-overcome-error-while-importing.html 共享 >>“如何在将 SQLPS 模块导入 Powershell 时克服错误?”

PS SQLSERVER:\> Import-Module “sqlps” -DisableNameChecking
PS SQLSERVER:\> cd SQL
PS SQLSERVER:\SQL> dir
  MachineName                     
  -----------                     
  PC181578                        

PS SQLSERVER:\SQL> cd LocalHost
PS SQLSERVER:\SQL\LocalHost> dir

但我收到以下错误并卡住了。我想我错过了一些愚蠢的东西。 .累死了,:(

Invoke-Sqlcmd : Invalid object name 'Users'.
At line:17 char:3
+   Invoke-Sqlcmd  @params
+   ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [Invoke-Sqlcmd], SqlPowerShellSqlExecutionException
+ FullyQualifiedErrorId : SqlError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

请求一些可以让我继续前进的建议。我觉得在建立联系的方法中遗漏了一些东西。

谢谢

H巴拉

【问题讨论】:

    标签: sql-server powershell azure arm-template


    【解决方案1】:

    RPC Locator 服务启动绝对是正确的步骤。它得到了警告并更正了本地查找。

    但我收到“无效对象错误”的原因是导入已完成,但尚未创建定义的所有架构。

    仔细观察发现以下内容:

    1. Get-AzureSqlDatabaseImportExportStatus 不返回任何状态。

    Get-AzureSqlDatabaseImportExportStatus -RequestId $ImportRequest.RequestGuid            
      -ServerName $deployParameters.Item('sqlserverName') 
      -Username $credential.UserName
    
    1. 尝试如下以编程方式了解进度,显示它卡在 5%,然后突然闪烁完成

          $ImportRequest = Start-AzureSqlDatabaseImport -SqlConnectionContext $SqlCtx -StorageContainer $Container -DatabaseName $deployParameters.Item('databaseName') -BlobName $BlobName
      
                          # Check the status of the import
                      Do
                      {
                          $importStatus = Get-AzureSqlDatabaseImportExportStatus -Request $importRequest
      
                          # Check if import failed
                          if($importStatus.Status -eq "Failed")
                          {
                              Write-Output -Message $importStatus.ErrorMessage
                              $importDone = 1;
                          }
      
                          # Check if import is completed
                          if($importStatus.Status -eq "Completed")
                          {
                              Write-Output "$(Get-Date -f $timeStampFormat) - Restore database complete"
                              $importDone = 1;
                          }
      
                          # If not failed or completed, return the status of the current import
                          if(($importStatus.Status -ne "Completed" -or $importStatus.Status -ne "Failed") -and $importDone -ne 1)
                          {
                              Write-Output "$(Get-Date -f $timeStampFormat) - Import status: $($importStatus.Status)"
                          }
      
                          # Added a sleep so that the Write-Output doesn't get flooded
                          Start-Sleep -s 3
                      }While($importDone -ne 1)
      
    2. 尝试直接在 PS 提示下让我导入已完成,但在 SSMS 上,我可以看到 仅创建了 30% 的表!!

        PS SQLSERVER:\> Get-AzureSqlDatabaseImportExportStatus -RequestId  
        $ImportRequest.RequestGuid -ServerName   
        $deployParameters.Item('sqlserverName') -Username $credential.UserName
        cmdlet Get-AzureSqlDatabaseImportExportStatus at command pipeline   position 1
        Supply values for the following parameters:
        (Type !? for Help.)
        Password: ABCEfg1pr0
      

    BlobUri : https://ABC.blob.core.windows.net/kind-snapshot/kind-snapshot.bacpac

    数据库名称:Pilotdbtrialrun

    错误消息:

    最后修改时间:2016 年 6 月 3 日下午 2:29:29

    排队时间:2016 年 6 月 3 日下午 2:27:42

    RequestId : 0f76af7b-7452-4cd4-a7a8-d6XXX4dc5923

    请求类型:导入

    服务器名称:pilotsrvrtrialrun.database.windows.net

    状态:已完成

    扩展数据:

    4.通过门户导入相同的 backpac 可以正确创建完整的数据库表。

    【讨论】:

    • 关于为什么通过 Powershell 和 Portal 进行 bacpac 导入时表现不同的任何建议?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-24
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 2017-11-17
    • 1970-01-01
    • 2021-10-03
    相关资源
    最近更新 更多