title: Powershell: deploying dacpac to SQL Server 2012 has error 'Unable to connect to master or target server'
body: <p>I can deploy dacpac to SQL Server 2012 using <code>sqlpackage.exe</code>. The SQL Server has Windows authentication. </p>
  
  <pre><code>"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
  </code></pre>
  
  <p>However it failed with PowerShell. The PowerShell script:</p>
  
  <pre><code>$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
  </code></pre>
  
  <p>The error:</p>
  
  <blockquote>
    <p>Exception: System.Management.Automation.MethodInvocationException: Exception calling "Deploy" with "4" argument(s): "Could not deploy package."</p>
    
    <p>Microsoft.SqlServer.Dac.DacServicesException: Could not deploy package. </p>
    
    <p>Microsoft.Data.Tools.Schema.Sql.Deployment.DeploymentFailedException: Unable to connect to master or target server 'test-dacpac1'. You must have a user with the same password in master or target server 'test-dacpac1'.</p>
  </blockquote>
  
  <p>Any thoughts please?</p>