我可以使用sqlpackage.exe
将dacpac部署到SQL Server 2012。 SQL Server具有Windows身份验证。
"C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\SqlPackage.exe" /a:Publish /sf:"C:\Users\xxx\Documents\visual studio 2015\Projects\yyy\Database1.dacpac" /tdn:test-dacpac1 /TargetServerName:.\sql12
然而,PowerShell失败了。 PowerShell脚本:
$dacpacFileName = "C:\Users\xxx\Documents\Visual Studio 2015\Projects\yyy\Database1.dacpac" $databaseServerName = ".\sql12"
$targetDatabaseName = "test-dacpac1"
$upgradeExisting = "True"
#http://blogs.msmvps.com/deborahk/deploying-a-dacpac-with-powershell/
add-type -path "C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\Microsoft.SqlServer.Dac.dll"
#service
$dacService = new-object Microsoft.SqlServer.Dac.DacServices "server=$databaseServerName"
#dacpac
$dp = [Microsoft.SqlServer.Dac.DacPackage]::Load($dacpacFileName)
#options
$options = New-Object Microsoft.SqlServer.Dac.DacDeployOptions
$options.GenerateSmartDefaults="True"
#deploy
$dacService.Deploy($dp, $targetDatabaseName, $upgradeExisting, $options)
#error
$error[0]|format-list -force
错误:
异常:System.Management.Automation.MethodInvocationException:异常调用"部署"用" 4"参数:"无法部署包。"
Microsoft.SqlServer.Dac.DacServicesException:无法部署包。
Microsoft.Data.Tools.Schema.Sql.Deployment.DeploymentFailedException:无法连接到主服务器或目标服务器' test-dacpac1'。您必须在主服务器或目标服务器中使用具有相同密码的用户' test-dacpac1'。
有什么想法吗?