2013-09-03 1 views
7

Visual Studio 2012를 사용하고 있으며 EF 6에서 Entity Framework 스택을 사용하고 있습니다. 마이그레이션을 추가하는 동안 모두 올바른 작업을 수행했지만 오류. 여기 SQL Server 2012를 사용하는 Entity Framework 6은 System.Data.Entity.Core.ProviderIncompatibleException을 제공합니다.

System.Data.Entity.Core.ProviderIncompatibleException

는 클래스

public class Order 
{ 
    public virtual int OrderID { get; set; } 
} 

컨텍스트 파일

public ShoppingCartContext() : base("ShoppingCartDb") 
{ 
     Database.SetInitializer<ShoppingCartContext>(new DropCreateDatabaseAlways<ShoppingCartContext>()); 
} 

protected override void OnModelCreating(DbModelBuilder modelBuilder) 
{ 
     #region Entity Framework 6 RC-1 
     modelBuilder.Properties().Where(x => x.Name == x.DeclaringType.ToString() + "ID") 
       .Configure(x => x.IsKey()); 

     modelBuilder.Properties<DateTime>() 
       .Configure(x => x.HasColumnType("datetime2")); 
     #endregion 

     modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); 
     base.OnModelCreating(modelBuilder); 
    } 

그리고 오류 때마다 점점 오전

<connectionStrings> 
    <add name="ShoppingCartDb" 
     connectionString="Server=Localhost;Database=ShoppingCartEfDb;User Id=sa;Password=xxxxxxxxxx" 
     providerName="System.Data.SqlClient" /> 
</connectionStrings> 

을 connctionstring의 web.config 파일 섹션입니다 나는 노력하고있다. g로 마이그레이션을 추가하려면 다음을 입력하십시오.

System.Data.Entity.Core.ProviderIncompatibleException: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct. ---> System.Data.Entity.Core.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. --->

System.Data.SqlClient.SqlException: 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)

+2

'base ("ShoppingCartDb")'대신'base ("name = ShoppingCartDb")'를 사용하지 않아야합니까? – Pawel

답변

21

시도해보십시오. ShoppingCartContext가있는 프로젝트가 시작 프로젝트인지 또는 add-migration 명령을 실행할 때 -startupprojectname ex 매개 변수가 포함되어 있는지 확인하십시오. add-migration -startupprojectname yourprojectname

+1

WebApi 프로젝트를 "시작 프로젝트"로 설정하는 것이 내 문제의 해결책이었습니다. 잘 잡으세요! – ilter

관련 문제