带有 SQL Server 2012 的实体框架 6 提供 System.Data.Entity.Core.ProviderIncompatibleException [英] Entity Framework 6 with SQL Server 2012 gives System.Data.Entity.Core.ProviderIncompatibleException

查看:27
本文介绍了带有 SQL Server 2012 的实体框架 6 提供 System.Data.Entity.Core.ProviderIncompatibleException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have Visual Studio 2012 and I'm using the Entity Framework stack with EF 6. I did all correct but while adding migration I am getting the error .

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

以及用于连接字符串的 web.config 文件部分

And the web.config file section for connctionstring

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

每当我尝试将迁移添加为:

I am getting the error whenever I am trying to add migration as :

System.Data.Entity.Core.ProviderIncompatibleException:从数据库获取提供者信息时出错.这可能是由实体框架使用不正确的连接字符串引起的.检查内部异常以获取详细信息并确保连接字符串正确.---> System.Data.Entity.Core.ProviderIncompatibleException:提供程序未返回 ProviderManifestToken 字符串.--->

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:建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误.服务器未找到或无法访问.验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接.(提供程序:SQL 网络接口,错误:26 - 错误定位服务器/指定的实例)

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

Try this. Make sure that the project that your ShoppingCartContext is in, is the start up project or when executing the add-migration command include the parameter -startupprojectname ex. add-migration -startupprojectname yourprojectname

这篇关于带有 SQL Server 2012 的实体框架 6 提供 System.Data.Entity.Core.ProviderIncompatibleException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆