0

I am creating a small app with EF code first and I want to call the update database command from the package manager console and target the database in my app.config which is a local .mdf.

I have this connection string in my app.config

<connectionStrings>
    <add name="EventsConnectionString"
    connectionString="Data Source=(localdb)\v11.0;Database=EventsApp;Trusted_Connection=Yes;" />
  </connectionStrings>

RegistrantContext class with connection string in constructor

using System.Data.Entity;
using EventsApp.Entities;

namespace EventsApp.Contexts.DataContexts
{
    public class RegistrantDb :DbContext
    {
        public RegistrantDb()
            : base("EventsConnectionString")
        {

        }

        public DbSet<Registrant> Registrants { get; set; }
    }
}

My file structure

enter image description here

And the command to update the database:

Update-Database -ConfigurationTypeName EventsApp.Contexts.DataContexts.RegistrantMigrations.Configuration -verbose

Error message

Error Number:-1,State:0,Class:20
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 believe my settings are wrong so it can't find Events.mdf. Does anyone know what I need to change?

nick gowdy
  • 6,191
  • 25
  • 88
  • 157

1 Answers1

0

You should always check if you use the correct project to apply updates to (either select the correct project from the "Default Project" dropdown at the top of the package manager console or you can add -ProjectName to your Update-Database command:

Update-Database -ProjectName EventsApp.Contexts -YourOtherOptions
Stephen Reindl
  • 5,659
  • 2
  • 34
  • 38