none
Error When Creating Database For First Time in Code First EF 5.0 RRS feed

  • Question

  • Hi,

    I'm trying out code first for the first time. I'm using EF 5.0 and .NET 4.5.

    I'm trying this in a multi-layered solution. I have a console app which is my UI, I have a Domain class library which will access my context, I have a model class library which contains my context and an entities class library which contains my entities. This is the basic architecture I use for model / database first EF.

    I have enabled migrations on the model class library and added some basic entities, a context and some simple code to add an entity and then retrieve it. 

    When I run my code (or perform a database-update) I get a SQL connection error:

    A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

    I am using VS2012, I do not have SQLExpress installed so I was expecting it to create the database in LocalDb?

    Any help would be greatly appreciated.

    thanks

    Stephen


    Stephen

    Friday, July 26, 2013 10:38 AM

Answers

  • Solved it,

    I needed to copy the contents of the app.config in my model class to the app.config in my console class (similar to copying the conn string when doing database first).

    <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="v11.0" />
          </parameters>
        </defaultConnectionFactory>
      </entityFramework>

    Once this was copied over and my application executed it generated the database!


    Stephen

    • Marked as answer by -Ozymandias- Friday, July 26, 2013 11:02 AM
    Friday, July 26, 2013 11:02 AM

All replies

  • Solved it,

    I needed to copy the contents of the app.config in my model class to the app.config in my console class (similar to copying the conn string when doing database first).

    <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="v11.0" />
          </parameters>
        </defaultConnectionFactory>
      </entityFramework>

    Once this was copied over and my application executed it generated the database!


    Stephen

    • Marked as answer by -Ozymandias- Friday, July 26, 2013 11:02 AM
    Friday, July 26, 2013 11:02 AM
  • Hi a2Ton,

    I am very glad that you have solved your problem by yourself and thanks for sharing your experience. If you have any other problem, welcome to post it in the MSDN forums.

    Thanks

    Best Regards


    Starain Chen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Saturday, July 27, 2013 3:42 PM
    Moderator