2013-09-03 3 views
7

J'ai Visual Studio 2012 et j'utilise la pile Entity Framework avec EF 6. J'ai tout fait correctement mais en ajoutant la migration, je reçois le Erreur .Entity Framework 6 avec SQL Server 2012 donne System.Data.Entity.Core.ProviderIncompatibleException

System.Data.Entity.Core.ProviderIncompatibleException

Voici les classes

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

Le fichier contexte

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); 
    } 

et la section de fichier web.config pour connctionstring

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

Je reçois l'erreur chaque fois Je suis tryin g pour ajouter la migration en tant que:

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

Ne devriez-vous pas utiliser 'base (" name = ShoppingCartDb ")' au lieu de 'base (" ShoppingCartDb ")'? – Pawel

Répondre

21

Essayez ceci. Assurez-vous que le projet dans lequel se trouve votre ShoppingCartContext est le projet de démarrage ou, lors de l'exécution de la commande add-migration, incluez le paramètre -startupprojectname ex. add-migration -startupprojectname votreprojetname

+1

Définir le projet WebApi comme le «projet de démarrage» était la solution à mon problème. Bonne prise! – ilter

Questions connexes