sql-server-2012 – 带有SQL Server 2012的Entity Framework 6提供了System.Data.Entity.Core.ProviderIncompatibleException

我有Visual Studio 2012,我正在使用EF 6的实体框架堆栈.我做的都正确但是在添加迁移时我收到了错误.

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

和connctionstring的web.config文件部分

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

每当我尝试添加迁移时,我都会收到错误

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)

解决方法

试试这个.确保ShoppingCartContext所在的项目是启动项目,或者在执行add-migration命令时包含参数-startupprojectname ex. add-migration -startupprojectname yourprojectname

相关文章

(一)日志传送架构 (1.1)相关服务器 主服务器 :用于生产的服务器,上面运行这生产SQL Server数据库...
(一)事故背景 最近在SQL Server 2012生产数据库上配置完事物复制(发布订阅)后,生产数据库业务出现了...
(一)测试目的 目前公司使用的SQL SERVER 2012高可用环境为主备模式,其中主库可执行读写操作,备库既...
(一)背景个人在使用sql server时,用到了sql server的发布订阅来做主从同步,类似MySQL的异步复制。在...
UNION和OR谓词 找出 product 和 product2 中售价高于 500 的商品的基本信息. select * from product wh...
datawhale组队学习task03