2017-03-05 50 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管理工作室檢查您的數據庫是否正在連接。

相關問題