gpt4 book ai didi

sql-server - 通过 Powershell 连接到 Azure SQL 数据库

转载 作者:行者123 更新时间:2023-12-03 00:14:55 26 4
gpt4 key购买 nike

我试图让 powershell 从本地连接到 Azure SQL 数据库。我尝试了以下代码片段

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

但是我收到了这个警告:

WARNING: Could not obtain SQL Server Service information. An attempt to connect to WMI on 'Microsoft.WindowsAzure.Commands.SqlDatabase.Types.ps1xml' failed with the following error: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

我认为,通过手动从组件服务链接打开 RPC Locator 服务来解决上述问题,由 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巴拉

最佳答案

RPC Locator 服务启动绝对是正确的步骤。它纠正了警告和本地查找。

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

仔细观察发现以下内容:

<强>1。 Get-AzureSqlDatabaseImportExportStatus 不返回任何状态。

Get-AzureSqlDatabaseImportExportStatus -RequestId $ImportRequest.RequestGuid            
-ServerName $deployParameters.Item('sqlserverName')
-Username $credential.UserName
  • 尝试按如下方式以编程方式了解进度,显示它卡在 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)
  • 直接尝试在 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

    DatabaseName : Pilotdbtrialrun

    ErrorMessage :

    LastModifiedTime : 6/3/2016 2:29:29 PM

    QueuedTime : 6/3/2016 2:27:42 PM

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

    RequestType : Import

    ServerName : pilotsrvrtrialrun.database.windows.net

    Status : Completed

    ExtensionData :

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

    关于sql-server - 通过 Powershell 连接到 Azure SQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37591951/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com