2016-08-05 5 views
3

dacpacをデプロイする以下の機能があります。私はdacpacの変数を渡す方法を見てきました。これは可能ですか?powershellを使用して変数を変更したdacpacをデプロイ

Function DeployDB { 

param( 
    [string]$SqlServerName = $(throw "Missing required parameter SqlServerName"), 
    [string]$SqlServerUserName = $(throw "Missing required parameter SqlServerUserName"), 
    [string]$SqlServerPassword = $(throw "Missing required parameter SqlServerPassword"), 
    [string]$dacpac = $(throw "Missing required parameter dacpac"), 
    [string]$dbname = $(throw "Missing required parameter dbname") 
    ) 

Write-Host "Deploying the DB with the following settings" 
Write-Host "Server Name: $SqlServerName" 
Write-Host "DACPAC: $dacpac" 
Write-Host "Name: $dbname" 

# load in DAC DLL, This requires config file to support .NET 4.0. 
# change file location for a 32-bit OS 
#make sure you 
add-type -path "C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\Microsoft.SqlServer.Dac.dll" 

# Create a DacServices object, which needs a connection string 
$dacsvcs = new-object Microsoft.SqlServer.Dac.DacServices "server=$SqlServerName;User ID=$SqlServerUserName;Password=$SqlServerPassword;" 

# register event. For info on this cmdlet, see http://technet.microsoft.com/en-us/library/hh849929.aspx 
register-objectevent -in $dacsvcs -eventname Message -source "msg" -action { out-host -in $Event.SourceArgs[1].Message.Message } | Out-Null 

# Load dacpac from file & deploy database 
$dp = [Microsoft.SqlServer.Dac.DacPackage]::Load($dacpac) 
$dacsvcs.Deploy($dp, $dbname, $true) 

# clean up event 
unregister-event -source "msg" 

} 
+0

dacpacのパス変数の意味について詳しく説明できますか?ところで、上記のパスはDACFxの非常に古いバージョンを使用しています。最新のバージョン(https://www.microsoft.com/en-us/download/details.aspx?id=53013)は、SQL Server \ 130 \ DAC \ binフォルダにインストールされます。 –

+0

次のSqlCmd変数の値が不足しています:DeploymentName。 (Microsoft.Data.Tools.Schema.Sql)渡す必要のある単一の変数があります – MrBeanzy

+0

SQLPackageをインストールする必要がなくなり、SQLPackageを含むNuGetパッケージをリリースしました。ここをクリックhttps://www.nuget.org/packages/Microsoft.Data.Tools.Msbuild –

答えて

1

次のように展開オプションを作成してみてくださいとDeploy()機能に四番目のパラメータとして渡すことができます。

$deployOptions = New-Object Microsoft.SqlServer.Dac.DacDeployOptions 
$deployOptions.SqlCommandVariableValues.Add("SqlCmdParamName", "ParamValue"); 
+1

$ deployOptions.SqlCmdVariableValuesの代わりに$ deployOptions.SqlCommandVariableValuesを試してみてください –

関連する問題