mardi 27 octobre 2015

Unit Tests using localdb and integrated security instead of connection string after migration to VS2015

I have a load of unit tests that were running fine in Visual Studio 2013. I dont know if it is related, but I can't think of what else might have changed. I have moved my project to VS2015.

Now whenever I run my unit tests, all the tests that use a data context fail with an error indicating they are trying to use (localdb)\V11.0 and integrated security to access the database.

However, my development database is on .\sqlexpress and has a SQL login.

I've been through every config file, including the app.config in the unit test project, and they all specify the correct database. If I debug step through the code I can reach the line where the data context is created and inspect its properties and see the connection string is wrong, but I can't see where it is coming from.

Here's the relevant bit of my test project's app.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://ift.tt/1eigFsq -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="speedEntitiesDev" connectionString="metadata=http://res*/mydb.csdl|res*/mydb.ssdl|res*/mydb.msl;provider=System.Data.SqlClient;provider connection string=&quot;Server=.\sqlexpress;Database=thedatabase;User ID=theuser;Password=thepassword;Connection Timeout=30;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="Server=.\sqlexpress;Database=thedatabase;User ID=theuser;Password=thepassword;Connection Timeout=30;MultipleActiveResultSets=True" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

When I step into the unit test this is what the property inspector says is the value of the connection string is:

"Data Source=(localdb)\\v11.0;Initial Catalog=thedatabase;Integrated Security=True"

Note that the database name is correct, but everything else is wrong.

I did previously have a database hosted locally in localdb but after upgrading my development computer I stopped using it.

Aucun commentaire:

Enregistrer un commentaire