title: Release Management will not deploy to a SQL 2014 database
body: <p>Using Microsoft's Release Management Server for Team Foundation Server 2013 v12.0.31101.0, I keep getting an error (included later). I can however successfully run the sqlpackage command from my local machine, the build server and the target SQL Server. </p>
  
  <p><strong>Steps</strong> taken: </p>
  
  <ul>
  <li>I took the dll's and the sqlpackage.exe from <code>C:\Program Files (x86)\Microsoft SQL Server\120\DAC\bin</code> and copied them to a folder on my desktop </li>
  <li>In Release Management, I created a new Tool with the command: <code>sqlpackage.exe /Action:Publish /SourceFile:__FileName__ /TargetDatabaseName:__DatabaseName__ /TargetServerName:__ServerName__</code> </li>
  <li>I then added the dll's and the SqlPackage.exe from the folder I created a step earlier </li>
  <li>Save and Close </li>
  <li>I then created a new component which basically just wraps this tool (The Build Drop Location is a backslash to indicate the dacpac is at the root of the build folder) </li>
  <li>I then selected the Tool I created and it filled in everything. I updated my release template to include and use the component </li>
  </ul>
  
  <p>Putting the folder I created on any desktop, I can run the following command and it run just perfectly </p>
  
  <pre><code>sqlpackage.exe /Action:Publish /SourceFile:MyDatabase.dacpac /TargetDatabaseName:MyDatabase /TargetServerName:MyDatabaseServer
  </code></pre>
  
  <p>I did this from my local PC, the Build Server and the SQL Server itself, but when I use Release Management, I get the error. </p>
  
  <p><strong>Error</strong>:</p>
  
  <pre><code>An unexpected failure occurred: The type initializer for 'Microsoft.SqlServer.Dac.DacPackage' threw an exception..
  
  Unhandled Exception: System.TypeInitializationException: The type initializer for 'Microsoft.SqlServer.Dac.DacPackage' threw an exception. ---&gt; System.TypeInitializationException: The type initializer for 'Microsoft.SqlServer.Dac.DacServices' threw an exception. ---&gt; System.TypeInitializationException: The type initializer for 'SqlSchemaModelStaticState' threw an exception. ---&gt; System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.SqlServer.TransactSql.ScriptDom, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
  </code></pre>
  
  <p><strong>Update 1</strong>: I noticed on the error email from Release Management that the Target Server was my web server and not the SQL Server, even though the SQL Server was correctly named in the command. I checked the log on the web server and found the errors.  I copied over my folder of dlls to the desktop and ran the script and voila, I was able to recreate the error. I checked the installed programs in Control Panel and noticed that the installed version of Transact-SQL ScriptDom was for 2012, version 11.0.2100.60. So I installed SSDT here. The installation failed because I don't have Visual Studio installed, but it still managed to install the 12.0.2000.8 versions of Transact-SQL ScriptDom and related dlls. When I ran the script again, it successfully published the database! However, when I tried to build from Release Management, I got a new error. </p>
  
  <pre><code>Publishing to database 'Logging' on server 'BYDWVCMNSQ01'.
  Initializing deployment (Start)
  Initializing deployment (Failed)
  *** Could not deploy package.
  Unable to connect to target server.
  </code></pre>
  
  <p><strong>Update 2</strong>: So, I've confirmed the reason it was failing at this point was because the account that the build server was using did not have a login account to the SQL Server. I added the account and then granted it ddladmin and securityadmin privileges at the database I'm targeting.  This yields a new error that I'm unable to create a new user, but at least I'm getting closer.</p>
  
  <p><strong>Final Update</strong>: I had to also grant sysadmin so the account could create a login. This allowed the deployment step in RM to succeed.  This obviously is not the way I will leave it, I'll either use a publish profile or command flags to prevent the dacpac from being created with security objects and let it run with least privilege.  </p>
  
  <p>The issue of getting RM to deploy to SQL 2014 has been solved. The main issue was in my release template, I placed the DACPAC component inline with the rest of the build for my web server.  This causes the DACPAC command to be run from the web server, and for that to work I had to install SSDT on the web server.  I don't like this, and I'll probably rearrange my release template so that the web server and sql server are parallel, but nested under the same rollback.   </p>