Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 5 always try to connect to sqlexpress instead of local db

I'm using Visual Studio Express for web to follow this tutorial http://msdn.microsoft.com/en-US/data/jj193542. The tutorial tells that

By convention DbContext has created a database for you.

If a local SQL Express instance is available (installed by default with Visual Studio 2010) then Code First has created the database on that instance If SQL Express isn’t available then Code First will try and use LocalDb (installed by default with Visual Studio 2012) The database is named after the fully qualified name of the derived context, in our case that is CodeFirstNewDatabaseSample.BloggingContext

So, it should use localdb. But when I try to access my model, I can see in debug that the connection string points to .\SQLEXPRESS, althought I don't have sqlexpress. So, I got a timeout exception ...

Why localdb isn't used ?

Note that if I set explicitly the connectionstring to localdb, it's working ... Note too, that if I use Vs Express for Desktop, it's working too...

What's wrong with the Vs Express for web ?

like image 965
Tim Avatar asked Apr 30 '13 10:04

Tim


1 Answers

EF Connections explained Tell EF the factory to use by default, eg

<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
  <parameters>
    <parameter value="Data Source=.; Integrated Security=True; MultipleActiveResultSets=True" />
  </parameters>
</defaultConnectionFactory>

like image 110
phil soady Avatar answered Sep 20 '22 17:09

phil soady