gpt4 book ai didi

PowerShell 使用 **DacServices** 和 SQLCMD 变量来部署 DACPAC

转载 作者:行者123 更新时间:2023-12-04 11:04:58 26 4
gpt4 key购买 nike

在 PowerShell 中,我正在使用 Microsoft.SqlServer.Dac.DacServices 和 Microsoft.SqlServer.Dac.DacDeployOptions 来部署/更新数据库 DACPAC。我遇到的问题是找到在哪里设置包所需的 SQLCMD 变量。

缩略样本

# Create a DacServices object, which needs a connection string 
$dacsvcs = New-Object Microsoft.SqlServer.Dac.DacServices "server=$sqlserver"

# Load dacpac from file
$dp = [Microsoft.SqlServer.Dac.DacPackage]::Load($dacpac)

# Deploy options
$deployOptions = New-Object Microsoft.SqlServer.Dac.DacDeployOptions
$deployOptions.IncludeCompositeObjects = $true

我知道我可以用 SqlPackage.exe 很好地输入这些,也许这就是我应该做的。但是在文档或网络知识中,我找不到一个使用 SQLCMD 变量作为选项的 DacServices 使用示例——SQLCMD 变量作为我项目 DACPAC 的必需参数。

最佳答案

您应该在 $deployOptions.SqlCommandVariableValues 属性中设置选项。这是一个 updateabase 字典 - 您不能分配新字典,但可以更新其中的键/值对。例如将变量“MyDatabaseRef”设置为“Database123”使用

$deployOptions.SqlCommandVariableValues.Add("MyDatabaseRef", "Database123");

API 引用是 here .

关于PowerShell 使用 **DacServices** 和 SQLCMD 变量来部署 DACPAC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28588932/

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