0
votes

I have problem with creating local db with EF code first. When I try create db with command update-database Visual Studio returns the 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)

In earlier project I haven't any problem with do that.

Context Class

public class Context : DbContext {

    public DbSet<Project> Projects { get; set; }
    public DbSet<Task> Tasks { get; set; }
    public DbSet<Team> Teams { get; set; }
    public DbSet<User> Users { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder) {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

        modelBuilder.Ignore<IIdentifableEntity>();

        modelBuilder.Entity<Project>().HasKey(p => p.Id).Ignore(p => p.EntityId);
        modelBuilder.Entity<Task>().HasKey(t => t.Id).Ignore(t => t.EntityId);
        modelBuilder.Entity<Team>().HasKey(t => t.Id).Ignore(t => t.EntityId);
        modelBuilder.Entity<User>().HasKey(u => u.Id).Ignore(u => u.EntityId);
    }

}

App.config

Thank you for any help.

1
Maybe showing a connection string could be relevant? - Gert Arnold
I'm using default connection string in app.config - user5559211
Please show it, thanks! - ErikEJ
@do you have an instance named mssqllocaldb? Can you connect to it using SSMS? - CodingYoshi
All works after reinstall SQL server. - user5559211

1 Answers

0
votes

Make sure your connection string is valid and working with the reference database associated with respective username and password. You can check your database is connecting using SQL server management studio.