title: sqlpackage.exe "Cannot open database" randomly occurs
body: <p>I am using sqlpackage.exe to create dynamic databases to run unit tests against. This work locally 100% of the time, but not in TFS. All the unit tests use integrated security for locahost\sqlexpress. TFS will randomly cause sqlpackage.exe to return the following error.</p>
  
  <p>For the unit tests, I am using the pattern described <a href="http://nicholas.piasecki.name/blog/2010/01/integration-testing-with-sql-server-express-2008-nhibernate-and-mstest/" rel="nofollow">here</a>, but with some modifications to use a dacpac with sqlpackage as oppose to the schema export feature of nhibernate.</p>
  
  <pre><code>sqlpackage error    : *** Could not deploy package.
  sqlpackage error    : Cannot open database "MessagesRepositoryTests" requested by the login. The login failed.
  sqlpackage error    : Login failed for user 'DOMAIN\TFSService'.
  </code></pre>
  
  <p>Other (random) errors include another line mentioning that it failed to import the target model.</p>
  
  <pre><code>sqlpackage error    : *** Could not deploy package.
  sqlpackage error    : Failed to import target model MessagesRepositoryTests. Detailed message Cannot open database "MessagesRepositoryTests" requested by the login. The login failed.
  sqlpackage error    : Login failed for user 'DOMAIN\TFSService'.
  sqlpackage error    : Cannot open database "MessagesRepositoryTests" requested by the login. The login failed.
  sqlpackage error    : Login failed for user 'DOMAIN\TFSService'.
  </code></pre>
  
  <p>"DOMAIN\TFSService" has been granted every server role (sysadmin, public, etc).</p>
  
  <p>Does anyone have a clue why this would show up intermitently throughout all of my tests? Remember, this occurs only from the TFS build automated unit tests.</p>