title: Octopus Deploy.ps1 DACPAC Deployment Fails
body: <p>I'm using Octopus on TeamCity to deploy a database to our production environment, but it keeps giving an error.</p>
  
  <p>Here is the Deploy.ps1 code:</p>
  
  <pre><code>$dbName = $OctopusParameters['DBName']
  $dbUser = $OctopusParameters['AdminDBUsername']
  $dbPassword = $OctopusParameters['AdminDBPassword']
  $dbSource = $OctopusParameters['DBDataSource']
  
  # Set params
  if (! $dbName)
  {
      Write-Host "Missing required variable dbName" -ForegroundColor Yellow
      exit 1
  }
  if (! $dbUser)
  {
      Write-Host "Missing required variable dbUser" -ForegroundColor Yellow
      exit 1
  }
  if (! $dbPassword)
  {
      Write-Host "Missing required variable dbPassword" -ForegroundColor Yellow
      exit 1
  }
  if (! $dbSource)
  {
      Write-Host "Missing required variable dbSource" -ForegroundColor Yellow
      exit 1
  }
  
  # Add the DLL
  # For 64-bit machines
  Add-Type -path ((Get-Item -Path ".\" -Verbose).FullName + "\bin\Microsoft.SqlServer.TransactSql.ScriptDom.dll")
  Add-Type -path ((Get-Item -Path ".\" -Verbose).FullName + "\bin\Microsoft.SqlServer.Dac.dll")
  
  # Create the connection string
  $d = New-Object Microsoft.SqlServer.Dac.DacServices ("data source=" + $dbSource + ";User Id = " + $dbUser + ";pwd=" + $dbPassword)
  
  #Load the dacpac
  $dacpac = ((Get-Item -Path ".\" -Verbose).FullName + "\DeployScripts\Database.dacpac")
  $dacpacoptions = ((Get-Item -Path ".\" -Verbose).FullName + "\DeployScripts\publish.xml")
  
  #Load dacpac from file &amp; deploy to database
  $dp = [Microsoft.SqlServer.Dac.DacPackage]::Load($dacpac)
  
  #Read a publish profile XML to get the deployment options
  $dacProfile = [Microsoft.SqlServer.Dac.DacProfile]::Load($dacpacoptions)
  
  # Deploy the dacpac
  $d.Deploy($dp, $dbName, $TRUE, $dacProfile.DeployOptions)
  </code></pre>
  
  <p>Here is the publish profile in case it matters:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    &lt;PropertyGroup&gt;
      &lt;IncludeCompositeObjects&gt;True&lt;/IncludeCompositeObjects&gt;
      &lt;TargetDatabaseName&gt;MyDatabase&lt;/TargetDatabaseName&gt;
      &lt;DeployScriptFileName&gt;MyDatabase.sql&lt;/DeployScriptFileName&gt;
      &lt;ProfileVersionNumber&gt;1&lt;/ProfileVersionNumber&gt;
      &lt;BlockWhenDriftDetected&gt;True&lt;/BlockWhenDriftDetected&gt;
      &lt;RegisterDataTierApplication&gt;True&lt;/RegisterDataTierApplication&gt;
    &lt;/PropertyGroup&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>Below is the error I'm getting:</p>
  
  <p>Exception calling "Deploy" with "4" argument(s):</p>
  
  <p>"An error occurred during deployment plan generation. Deployment cannot continue."</p>
  
  <p>At Deploy.ps1:60 char:2</p>
  
  <p>$d.Deploy($dp, $dbName, $TRUE, $dacProfile.DeployOptions)</p>
  
  <p>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p>
  
  <p>CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException</p>
  
  <p>FullyQualifiedErrorId : DacServicesException</p>
  
  <p>Does anyone have any ideas what can be causing this? And how to fix it? Thanks in advance!</p>