Data driven unit test in combination with LocalDB not working in VSTS
<p>I have a problem running data driven unit tests (MSTest) in VSTS. My situation is the following:
In my C# solution I have a MSTest-test project which contains three test classes that contain data driven test methods.
These methods used to work with an attached MDF-file as data source, but for reasons of maintainability I added a database-project to my solution which contains the scripts to create and fill a database with my test data.</p>

<p>The test-project also contains an initialize method (marked with the <code>AssemblyInitialize</code> attribute) which deploys the dacpac from the database-project) to a LocalDB-instance. For this deployment I use the <code>Microsoft.SqlServer.DACFx</code> NuGet-package.</p>

<p>The data driven test methods all use the following connection string 
    <code>Data Source=(LocalDB)\v11.0;Initial Catalog=Enkoni_Validation_Tests;Integrated Security=True;Connect Timeout=30</code>
The problem is that this solution workes locally without any problems, but when I trigger a build on VSTS, most of the tests run fine, but one test class constantly failes with the message </p>

<blockquote>
  <p>"The unit test adapter failed to connect to the data source or to read the data. (...) Error details: Cannot open database "Enkoni_Validation_Tests" requested by the login. The login failed."</p>
</blockquote>

<p>The testmethods in the other two classes run without any problems. Since all three test classes are part of the same project, I assume the initialization (the deployment of the DacPac) runs without problems. 
Has anyone experienced a similar problem or does anyone know how to solve this?</p>

<p>Edit (added some additional information): the build runs on a hosted build agent and it's always the same test that fails. I have considered that maybe there is some sort of limitation on how many connections can be made to the LocalDB database, but I can't find any information that supports this theory. And since all my tests run sequential, I also don't expect that there are many (or even more than one) connections.</p>