【问题标题】:The term 'Microsoft.SqlServer.Dac.BacPackage::Load' is not recognized无法识别术语“Microsoft.SqlServer.Dac.BacPackage::Load”
【发布时间】:2018-08-07 15:21:44
【问题描述】:

我从 azure sql db 创建了一个 bacpac,将其复制到 blob,然后从 blob 将其在本地下载。

我在 powershell 中运行这段代码

Add-Type -path "C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin\Microsoft.SqlServer.Dac.dll"
$restoredDatabaseName = 'AuditTest'
$bacpacFile = "H:\backup\audit\audit.bacpac"
$conn = "Data Source=.;Initial Catalog=master;Connection Timeout=0;Integrated Security=True;"

$importBac = New-Object Microsoft.SqlServer.Dac.DacServices $conn
$loadBac = Microsoft.SqlServer.Dac.BacPackage::Load($bacpacFile)
$importBac.ImportBacpac($loadBac, $restoredDatabaseName)

#Clean up
$loadBac.Dispose()

恢复这个错误:

Microsoft.SqlServer.Dac.BacPackage::Load : The term 'Microsoft.SqlServer.Dac.BacPackage::Load' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the 
name, or if a path was included, verify that the path is correct and try again.

我也尝试使用导入数据层向导,但出现以下错误。

Could not load file or assembly 'Microsoft.SqlServer.Dac, Version=13.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. (Microsoft.SqlServer.Management.Dac.DacWizard)

这让我发疯了,我发现了一些关于注册表黑客等向导错误的事情,对 powershell 没有任何帮助。

SQL Azure DB PRS1 在 Azure VM 中恢复到 SQL 2016。

【问题讨论】:

    标签: powershell azure-sql-database sql-server-2016


    【解决方案1】:

    调用静态方法时,完整的类型名称放在方括号中。

    应该是这样的:

    Add-Type -path "C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin\Microsoft.SqlServer.Dac.dll"
    $restoredDatabaseName = 'AuditTest'
    $bacpacFile = "H:\backup\audit\audit.bacpac"
    $conn = "Data Source=.;Initial Catalog=master;Connection Timeout=0;Integrated Security=True;"
    
    $importBac = New-Object Microsoft.SqlServer.Dac.DacServices $conn
    $loadBac = [Microsoft.SqlServer.Dac.BacPackage]::Load($bacpacFile)
    $importBac.ImportBacpac($loadBac, $restoredDatabaseName)
    
    #Clean up
    $loadBac.Dispose()
    

    【讨论】:

    • 非常感谢,刚接触powershell,只是复制我在网上找到的示例。现在试一试,似乎还没有失败。
    • 它工作。太棒了。
    猜你喜欢
    • 2020-02-14
    • 2020-03-03
    • 1970-01-01
    • 1970-01-01
    • 2022-08-07
    • 2016-11-05
    • 2021-07-02
    • 2017-11-14
    • 1970-01-01
    相关资源
    最近更新 更多