2017-03-05 108 views
0

我有问题先用EF代码创建本地数据库。当我尝试创建数据库使用命令update-database Visual Studio中返回错误:使用实体框架创建本地数据库代码优先

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)

在早期的项目,我没有任何问题,做到这一点。

上下文类

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

感谢您的任何帮助。

+1

也许显示连接字符串可能是相关的? –

+0

我在app.config中使用默认连接字符串 –

+0

请显示它,谢谢! – ErikEJ

回答

0

确保您的连接字符串是有效的,并使用与相应用户名和密码关联的参考数据库。 您可以使用SQL Server管理工作室检查您的数据库是否正在连接。