Changing EF’s default connection factory from LocalDb to Sql Server

When you create a new project that makes use of Entity Framework 5, you'll notice how it uses LocalDb by default now. But let's assume you have a fully working instance of Sql Server that you wish to work against instead of LocalDb. How do you tell EF to use it? Simple, modify your application's config file. If you are running a web service or a website, your config file is web.config. If you are running a console application or a windows application, look for app.config.



    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">


        <parameter value="v11.0" />




Now, replace that portion of the configuration to make use of Sql Server instead of LocalDb.

Sql Server


    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">


        <parameter value="Data Source=.; Integrated Security=True; MultipleActiveResultSets=True" />




You only need to change the configuration to match your appropriate connection string.


Comments (12)
  1. More a question than a comment, but how would you change this for Oracle 11g?

  2. Rich says:

    Thanks. Helped me get deployed.

  3. Brian says:

    Is there a way to turn it off or to ignore the parameters?

    I don't want to track another Connection String outside of the connectionStrings section.

  4. John Ortiz Ordoñez (InfZero) says:

    I'm following the examples of `Microsoft ADO.NET Entity Framework Step by Step` book, but I was stucked in the example about Code First Workflow. In it there is no any hint about the database server that must be used to automatically créate the database, its tables, and the sample data.

    …Then I followed your proposed solution and it worked smoothly.


  5. Ehasan says:

    yes, It works

  6. Vahid says:


  7. Will W says:

    Thanks a bunch. This was very confusing.

  8. SM says:

    Thanks; it works

  9. Big Thanks - says:

    Great tip! simple and useful!

  10. Ryan says:

    Thanks! I wish there was an automated way to switch data providers in Visual Studio. Maybe there is! Comment. (Note: I know how to connect to a data source with EF, etc.)

  11. Metin says:

    Thank you; 🙂

  12. Good Stuff says:

    It's like you read my mind simply by querying for defaultConnectionFactory. Much obliged for your post!

Comments are closed.

Skip to main content